Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #4 from jcugat/loginview_methods

Merged LoginView post() method into form_valid() and form_invalid()
  • Loading branch information...
commit 718d10eb4f7c77931ee234d6df095a4b714e4a98 2 parents eb62e31 + 31ed7ab
Stefan Foulis authored
Showing with 11 additions and 15 deletions.
  1. +11 −15 class_based_auth_views/views.py
26 class_based_auth_views/views.py
View
@@ -40,10 +40,19 @@ def dispatch(self, *args, **kwargs):
def form_valid(self, form):
"""
The user has provided valid credentials (this was checked in AuthenticationForm.is_valid()). So now we
- can log him in.
+ can check the test cookie stuff and log him in.
"""
+ self.check_and_delete_test_cookie()
login(self.request, form.get_user())
- return HttpResponseRedirect(self.get_success_url())
+ return super(LoginView, self).form_valid(form)
+
+ def form_invalid(self, form):
+ """
+ The user has provided invalid credentials (this was checked in AuthenticationForm.is_valid()). So now we
+ set the test cookie again and re-render the form with errors.
+ """
+ self.set_test_cookie()
+ return super(LoginView, self).form_invalid(form)
def get_success_url(self):
if self.success_url:
@@ -75,19 +84,6 @@ def get(self, request, *args, **kwargs):
self.set_test_cookie()
return super(LoginView, self).get(request, *args, **kwargs)
- def post(self, request, *args, **kwargs):
- """
- Same as django.views.generic.edit.ProcessFormView.post(), but adds test cookie stuff
- """
- form_class = self.get_form_class()
- form = self.get_form(form_class)
- if form.is_valid():
- self.check_and_delete_test_cookie()
- return self.form_valid(form)
- else:
- self.set_test_cookie()
- return self.form_invalid(form)
-
class LogoutView(TemplateResponseMixin, View):
template_name = "registration/logout.html"
Please sign in to comment.
Something went wrong with that request. Please try again.