summaryrefslogtreecommitdiff
path: root/django/contrib/auth/forms.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2017-10-11 21:39:22 -0700
committerTim Graham <timograham@gmail.com>2017-10-23 09:10:45 -0400
commit6ed347d8518e23d7e453bdb21f7fa59ce2c4a885 (patch)
treee5816cf2283b6d956120a59a76b3baeb1f90c894 /django/contrib/auth/forms.py
parent7fb913c80555594a6dd756733fdb5869d5dba213 (diff)
Fixed #28706 -- Moved AuthenticationFormn invalid login ValidationError to a method for reuse.
Diffstat (limited to 'django/contrib/auth/forms.py')
-rw-r--r--django/contrib/auth/forms.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index 3b14a1791e..2c038e8111 100644
--- a/django/contrib/auth/forms.py
+++ b/django/contrib/auth/forms.py
@@ -192,11 +192,7 @@ class AuthenticationForm(forms.Form):
if username is not None and password:
self.user_cache = authenticate(self.request, username=username, password=password)
if self.user_cache is None:
- raise forms.ValidationError(
- self.error_messages['invalid_login'],
- code='invalid_login',
- params={'username': self.username_field.verbose_name},
- )
+ raise self.get_invalid_login_error()
else:
self.confirm_login_allowed(self.user_cache)
@@ -227,6 +223,13 @@ class AuthenticationForm(forms.Form):
def get_user(self):
return self.user_cache
+ def get_invalid_login_error(self):
+ return forms.ValidationError(
+ self.error_messages['invalid_login'],
+ code='invalid_login',
+ params={'username': self.username_field.verbose_name},
+ )
+
class PasswordResetForm(forms.Form):
email = forms.EmailField(label=_("Email"), max_length=254)