Beispiel #1
0
def authenticateuser(request):
    if request.user.is_authenticated:
        return render(request, 'userprofile.html')
    else:
        if request.method == 'POST':
            if 'registrationform' in request.POST:
                registrationform = RegistrationForm(data=request.POST)
                loginform = LogInForm()

                if registrationform.is_valid():
                    username = registrationform.cleaned_data['username']
                    password = registrationform.cleaned_data['password1']
                    registrationform.save()
                    user = authenticate(username=username, password=password)
                    # LogIn user as soon as registered
                    login(request, user)
                    return redirect('/')
            else:
                loginform = LogInForm(data=request.POST)
                registrationform = RegistrationForm()

                if loginform.is_valid():
                    login(request, loginform.get_user())
                    return redirect('/')
        else:
            registrationform = RegistrationForm()
            loginform = LogInForm()

        return render(request, 'authentication.html', {'registrationform': registrationform, 'loginform': loginform})
Beispiel #2
0
def register(request):
    # registered = False
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()

            return redirect('login')

    else:
        form = RegistrationForm()

    return render(request, 'registration/signup.html', {'form': form})