Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. class LoginView(View):
  2.  
  3. def get(self, request, *args, **kwargs):
  4. # create a new form instance
  5. form = forms.LoginForm()
  6.  
  7. return render(request, "login.html", {'form': form})
  8.  
  9. def post(self, request, *args, **kwargs):
  10. # create a form instance and populate it with data from the request
  11. form = forms.LoginForm(request.POST)
  12. # check whether is valid
  13. if form.is_valid():
  14. form.save()
  15. user_name = form.cleaned_data['username']
  16. password = form.cleaned_data['password']
  17. user = authenticate(username=user_name, password=password)
  18. if user is not None:
  19. login(request, user)
  20. return HttpResponseRedirect('/boletim/')
  21. else:
  22. return HttpResponseRedirect('/login/')
  23. else:
  24. return HttpResponseRedirect('/login/')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement