1
0
mirror of https://github.com/django/django.git synced 2025-03-31 19:46:42 +00:00
shanghui ebb998976e Fixed #28751 -- Corrected the error message for inactive users in AdminAuthenticationForm.
Thanks SeungWon Kang for the report and Tim Graham for the review.
2017-11-08 09:39:12 -05:00

31 lines
1023 B
Python

from django import forms
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm
from django.utils.translation import gettext_lazy as _
class AdminAuthenticationForm(AuthenticationForm):
"""
A custom authentication form used in the admin app.
"""
error_messages = dict(AuthenticationForm.error_messages)
error_messages.update({
'invalid_login': _(
"Please enter the correct %(username)s and password for a staff "
"account. Note that both fields may be case-sensitive."
),
})
required_css_class = 'required'
def confirm_login_allowed(self, user):
super().confirm_login_allowed(user)
if not user.is_staff:
raise forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={'username': self.username_field.verbose_name}
)
class AdminPasswordChangeForm(PasswordChangeForm):
required_css_class = 'required'