Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def getLogin(request):
- if request.user.is_authenticated:
- ...
- # operations and context creation
- ...
- return render(request, 'myapp:home', context)
- else:
- if request.method == "POST":
- email = request.POST['mail']
- password = request.POST['psw']
- user = authenticate(request, username=email, password=password)
- if user is not None:
- auth_login(request, user) #the Django login renamed as auth_login
- ...
- # operations and context creation
- ...
- return redirect("/home", context)
- else:
- return redirect('/login/error', errorLogin='error')
- # shows the same page but with a login error message
- else:
- return redirect("myapp:errorpage")
- def home(request):
- if request.user.is_authenticated:
- # operations and context creation
- return render(request, 'users/home.html', context)
- else:
- return redirect("myapp:errorpage")
- #goes into a error page
- def testHomeWithLogin(self):
- user = User.objects.create(username="qwerty@gmail.com",
- email="qwerty@gmail.com", password="qwerty")
- print(user.username)
- response = self.client.post("/login/#", {
- "mail": "qwerty@gmail.com", "psw": "qwerty"
- })
- print(response.context["mail"])
Add Comment
Please, Sign In to add comment