Beispiel #1
0
def newUser(request):
    form = UserCreationForm()
    print("In new User")
    if form.is_valid():
        print("Form is valid")
        user = User.objects.create_user(form.cleaned_data["username"], form.cleaned_data["password"])
        form = loginForm()
        return render(request, "contacts/login.html", {"form": form})
    else:
        form = UserCreationForm()
        return render(request, "contacts/newUser.html", {"form": form})
Beispiel #2
0
def login(request):
    if request.method == "POST":
        form = loginForm(request.POST)
        print("Recieved the login")
        if form.is_valid():
            print("It is valid")
            user = authenticate(username=form.cleaned_data["username"], password=form.cleaned_data["password"])
            print("username is " + form.cleaned_data["username"])
            print("password is " + form.cleaned_data["password"])
            print(user)
            if user is not None:
                print("it is not none")
                if user.is_active:
                    print("it is active")
                    return HttpResponseRedirect("/contacts/")
            else:
                form = loginForm()
                return render(request, "contacts/login.html", {"form": form})
    else:
        form = loginForm()

    return render(request, "contacts/login.html", {"form": form})
Beispiel #3
0
def logout_view(request):
    logout(request)
    form = loginForm()
    return HttpResponseRedirect("/contacts/login")