Exemplo n.º 1
0
def login_view(request):
    context = {}
    redirect_to = request.GET.get('next', '')

    user = request.user
    if user.is_authenticated:
        return redirect('home')

    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            email = request.POST['email']
            password = request.POST['password']
            user = authenticate(email=email, password=password)

            if user:
                login(request, user)
                if redirect_to == "" or redirect_to is None:
                    return redirect("home")
                return HttpResponseRedirect(redirect_to)

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form
    if redirect_to != "" or redirect_to is not None:
        context['redirect_to'] = redirect_to

    # print(form)
    return render(request, "accounts/login.html", context)
Exemplo n.º 2
0
def login_view(request):
	context = {}

	user = request.user
	#First check if user is already logged in.
	if user.is_authenticated:
		return redirect('home')

	#If user try to Login..
	if request.POST:
		form = AccountAuthenticationForm(request.POST)
		if form.is_valid():
			email = request.POST['email']
			password = request.POST['password']
			user =authenticate(email=email, password=password)

			#if Login and account exist, then login user..
			if user:
				login(request, user)
				return redirect('home')

	else:
		form = AccountAuthenticationForm()

	context['login_form'] = form
	return render(request, 'accounts/login.html', context)
Exemplo n.º 3
0
def login_view(request):
    context = {}

    user = request.user
    if user.is_authenticated:
        return redirect("home")

    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)

            if user:
                login(request, user)
                return redirect("dashboard")

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form

    # print(form)
    return render(request, "accounts/login.html", context)
Exemplo n.º 4
0
def login(request):
    context = {}
    user = request.user
    if user.is_authenticated:
        return redirect('dashboard')

    if request.method == "POST":
        # Añadimos los datos recibidos al formulario
        form = AccountAuthenticationForm(data=request.POST)
        # Si el formulario es válido...
        if form.is_valid():
            # Recuperamos las credenciales validadas
            email = request.POST['email']
            password = request.POST['password']

            # Verificamos las credenciales del usuario
            user = authenticate(email=email, password=password)

            # Si existe un usuario con ese nombre y contraseña
            if user:
                # Hacemos el login manualmente
                do_login(request, user)
                # Y le redireccionamos a la portada
                return redirect('dashboard')
    else:
        form = AccountAuthenticationForm()
    context = {'form': form}
    # Si llegamos al final renderizamos el formulario
    return render(request, "login.html", context)
Exemplo n.º 5
0
def login_view(request):

    context = {}

    user = request.user
    if user.is_authenticated:
        return redirect("core:index")

    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            email = request.POST['email']
            password = request.POST['password']
            user = authenticate(email=email, password=password)

            if user:
                login(request, user)
                return redirect("core:index")

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form

    # print(form)
    return render(request, "account/login.html", context)
Exemplo n.º 6
0
def loginPage(request):
    user = request.user
    if user.is_authenticated:
        return redirect('home')
    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            email = request.POST['email']
            password = request.POST['password']
            user = authenticate(email=email, password=password)

            if user:
                login(request, user)
                return redirect("home")
    else:
        form = AccountAuthenticationForm()
    context = {'form': form}
    return render(request, 'login.html', context)
Exemplo n.º 7
0
def login_view(request):
    context = {}
    user = request.user

    if user.is_authenticated:
        return redirect('profile')

    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user:
                login(request, user)
                return redirect('profile')

    else:
        form = AccountAuthenticationForm()

    context['login_form'] = form
    return render(request, 'accounts/login.html', context)
Exemplo n.º 8
0
def login_view(request, *args, **kwargs):
    template_name = 'accounts/login.html'
    context = {}

    if request.user.is_authenticated:
        return redirect('home')

    destination = get_redirect_if_exists(request)
    if request.POST:
        form = AccountAuthenticationForm(request.POST)
        if form.is_valid():
            email = request.POST['email']
            password = request.POST['password']
            user = authenticate(email=email, password=password)
            if user:
                login(request, user)
                destination = get_redirect_if_exists(request)
                if destination:
                    return redirect(destination)
                return redirect('home')
        else:
            context['login_form'] = form

    return render(request, template_name, context)