Guest User

Untitled

a guest
Jun 22nd, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. def getLogin(request):
  2. if request.user.is_authenticated:
  3. ...
  4. # operations and context creation
  5. ...
  6. return render(request, 'myapp:home', context)
  7. else:
  8. if request.method == "POST":
  9. email = request.POST['mail']
  10. password = request.POST['psw']
  11. user = authenticate(request, username=email, password=password)
  12. if user is not None:
  13. auth_login(request, user) #the Django login renamed as auth_login
  14. ...
  15. # operations and context creation
  16. ...
  17. return redirect("/home", context)
  18. else:
  19. return redirect('/login/error', errorLogin='error')
  20. # shows the same page but with a login error message
  21. else:
  22. return redirect("myapp:errorpage")
  23.  
  24. def home(request):
  25. if request.user.is_authenticated:
  26. # operations and context creation
  27. return render(request, 'users/home.html', context)
  28. else:
  29. return redirect("myapp:errorpage")
  30. #goes into a error page
  31.  
  32. def testHomeWithLogin(self):
  33. user = User.objects.create(username="qwerty@gmail.com",
  34. email="qwerty@gmail.com", password="qwerty")
  35. print(user.username)
  36. response = self.client.post("/login/#", {
  37. "mail": "qwerty@gmail.com", "psw": "qwerty"
  38. })
  39. print(response.context["mail"])
Add Comment
Please, Sign In to add comment