You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
999 B

  1. from __future__ import unicode_literals
  2. from django import forms
  3. from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm
  4. from django.utils.translation import ugettext_lazy as _
  5. class AdminAuthenticationForm(AuthenticationForm):
  6. """
  7. A custom authentication form used in the admin app.
  8. """
  9. error_messages = {
  10. 'invalid_login': _("Please enter the correct %(username)s and password "
  11. "for a staff account. Note that both fields may be "
  12. "case-sensitive."),
  13. }
  14. required_css_class = 'required'
  15. def confirm_login_allowed(self, user):
  16. if not user.is_active or not user.is_staff:
  17. raise forms.ValidationError(
  18. self.error_messages['invalid_login'],
  19. code='invalid_login',
  20. params={'username': self.username_field.verbose_name}
  21. )
  22. class AdminPasswordChangeForm(PasswordChangeForm):
  23. required_css_class = 'required'