Example #1
0
def sign_up(request):
    form = LoginForm(request.POST)
    if form.is_valid():
        user = form.save()
        user.set_password(user.password)
        user.save()
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password')
        user = authenticate(username=username, password=password)
        login(request, user)
        return redirect('src:home')
    else:
        form = LoginForm()
    return render(request, 'login.html', {'login_form': form})
Example #2
0
    def post(self, request):
        form = LoginForm(request, data=request.POST)

        if form.is_valid():
            # Check where should the user be redirected
            next_redirect = request.POST.get('next', '')
            if not is_safe_url(url=next_redirect,
                               allowed_hosts=[request.get_host()]):
                next_redirect = reverse('/')

            auth_login(request, form.get_user())
            messages.info(request, 'Logged in as {}.'.format(request.user))
            return HttpResponseRedirect(next_redirect)

        return render(request, self.template, {'form': form})
Example #3
0
def login_page(request):
    form = LoginForm(request.POST or None)
    print("User Logged in => ", request.user.is_authenticated)
    context = {
        "title": 'Form One',
        "content": 'Welcome to Login page',
        "form": form
    }
    if form.is_valid():
        print(form.cleaned_data)
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password')
        user = authenticate(request, username=username, password=password)
        print("User Logged in => ", request.user.is_authenticated)
        if user is not None:
            login(request, user)
            print("User Logged in => ", request.user.is_authenticated)
            context['form'] = LoginForm()
            return redirect('index')
        else:
            print("error in login")
            return redirect('login')
    return render(request, 'login.html', context)