Loading django/contrib/admin/forms.py +8 −4 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ from django.contrib.auth import authenticate from django.contrib.auth.forms import AuthenticationForm from django.utils.translation import ugettext_lazy ERROR_MESSAGE = ugettext_lazy("Please enter the correct username and password " "for a staff account. Note that both fields are case-sensitive.") ERROR_MESSAGE = ugettext_lazy("Please enter the correct %(username)s and password " "for a staff account. Note that both fields may be case-sensitive.") class AdminAuthenticationForm(AuthenticationForm): Loading @@ -26,8 +26,12 @@ class AdminAuthenticationForm(AuthenticationForm): if username and password: self.user_cache = authenticate(username=username, password=password) if self.user_cache is None: raise forms.ValidationError(message) raise forms.ValidationError(message % { 'username': self.username_field.verbose_name }) elif not self.user_cache.is_active or not self.user_cache.is_staff: raise forms.ValidationError(message) raise forms.ValidationError(message % { 'username': self.username_field.verbose_name }) self.check_for_test_cookie() return self.cleaned_data django/contrib/auth/forms.py +7 −5 Original line number Diff line number Diff line Loading @@ -148,8 +148,8 @@ class AuthenticationForm(forms.Form): password = forms.CharField(label=_("Password"), widget=forms.PasswordInput) error_messages = { 'invalid_login': _("Please enter a correct username and password. " "Note that both fields are case-sensitive."), 'invalid_login': _("Please enter a correct %(username)s and password. " "Note that both fields may be case-sensitive."), 'no_cookies': _("Your Web browser doesn't appear to have cookies " "enabled. Cookies are required for logging in."), 'inactive': _("This account is inactive."), Loading @@ -168,8 +168,8 @@ class AuthenticationForm(forms.Form): # Set the label for the "username" field. UserModel = get_user_model() username_field = UserModel._meta.get_field(UserModel.USERNAME_FIELD) self.fields['username'].label = capfirst(username_field.verbose_name) self.username_field = UserModel._meta.get_field(UserModel.USERNAME_FIELD) self.fields['username'].label = capfirst(self.username_field.verbose_name) def clean(self): username = self.cleaned_data.get('username') Loading @@ -180,7 +180,9 @@ class AuthenticationForm(forms.Form): password=password) if self.user_cache is None: raise forms.ValidationError( self.error_messages['invalid_login']) self.error_messages['invalid_login'] % { 'username': self.username_field.verbose_name }) elif not self.user_cache.is_active: raise forms.ValidationError(self.error_messages['inactive']) self.check_for_test_cookie() Loading Loading
django/contrib/admin/forms.py +8 −4 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ from django.contrib.auth import authenticate from django.contrib.auth.forms import AuthenticationForm from django.utils.translation import ugettext_lazy ERROR_MESSAGE = ugettext_lazy("Please enter the correct username and password " "for a staff account. Note that both fields are case-sensitive.") ERROR_MESSAGE = ugettext_lazy("Please enter the correct %(username)s and password " "for a staff account. Note that both fields may be case-sensitive.") class AdminAuthenticationForm(AuthenticationForm): Loading @@ -26,8 +26,12 @@ class AdminAuthenticationForm(AuthenticationForm): if username and password: self.user_cache = authenticate(username=username, password=password) if self.user_cache is None: raise forms.ValidationError(message) raise forms.ValidationError(message % { 'username': self.username_field.verbose_name }) elif not self.user_cache.is_active or not self.user_cache.is_staff: raise forms.ValidationError(message) raise forms.ValidationError(message % { 'username': self.username_field.verbose_name }) self.check_for_test_cookie() return self.cleaned_data
django/contrib/auth/forms.py +7 −5 Original line number Diff line number Diff line Loading @@ -148,8 +148,8 @@ class AuthenticationForm(forms.Form): password = forms.CharField(label=_("Password"), widget=forms.PasswordInput) error_messages = { 'invalid_login': _("Please enter a correct username and password. " "Note that both fields are case-sensitive."), 'invalid_login': _("Please enter a correct %(username)s and password. " "Note that both fields may be case-sensitive."), 'no_cookies': _("Your Web browser doesn't appear to have cookies " "enabled. Cookies are required for logging in."), 'inactive': _("This account is inactive."), Loading @@ -168,8 +168,8 @@ class AuthenticationForm(forms.Form): # Set the label for the "username" field. UserModel = get_user_model() username_field = UserModel._meta.get_field(UserModel.USERNAME_FIELD) self.fields['username'].label = capfirst(username_field.verbose_name) self.username_field = UserModel._meta.get_field(UserModel.USERNAME_FIELD) self.fields['username'].label = capfirst(self.username_field.verbose_name) def clean(self): username = self.cleaned_data.get('username') Loading @@ -180,7 +180,9 @@ class AuthenticationForm(forms.Form): password=password) if self.user_cache is None: raise forms.ValidationError( self.error_messages['invalid_login']) self.error_messages['invalid_login'] % { 'username': self.username_field.verbose_name }) elif not self.user_cache.is_active: raise forms.ValidationError(self.error_messages['inactive']) self.check_for_test_cookie() Loading