#28751: Add an error message for inactive user login in AdminAuthenticationForm
-------------------------------------+-------------------------------------
     Reporter:  SeungWon Kang        |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  contrib.admin        |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by SeungWon Kang:

Old description:

> In admin login site, I found that error message for 'inactive' user does
> not exist. (In AuthenticationForm it exists) I know default BackEnd
> checks the inactive in user_can_authenticate() method, but I think this
> error message is helpful if using other BackEnd like
> AllowAllUsersModelBackEnd.
>
> In AuthenticationForm,
> {{{
>     def confirm_login_allowed(self, user):
>         ...
>         if not user.is_active:
>             raise forms.ValidationError(
>                 self.error_messages['inactive'],
>                 code='inactive',
>             )
> }}}
>
> but in AdminAuthenticationForm,
>
> {{{
>     def confirm_login_allowed(self, user):
>         if not user.is_active or not user.is_staff:
>             raise forms.ValidationError(
>                 self.error_messages['invalid_login'],
>                 code='invalid_login',
>                 params={'username': self.username_field.verbose_name}
>             )
> }}}

New description:

 In admin login site, I found that ValidationError message for 'inactive'
 user does not exist. (In AuthenticationForm it exists) I know default
 BackEnd checks the is_active in user_can_authenticate() method, but I
 think adding this error message would be helpful if using other BackEnd
 like AllowAllUsersModelBackEnd.

 In AuthenticationForm, it shows inactive error message to the inactive
 user(user that `is_active=False`)
 {{{
     def confirm_login_allowed(self, user):
         ...
         if not user.is_active:
             raise forms.ValidationError(
                 self.error_messages['inactive'],
                 code='inactive',
             )
 }}}

 but in AdminAuthenticationForm, it shows invalid_login error message to
 the inactive user(user that `is_active=False`)

 {{{
     def confirm_login_allowed(self, user):
         if not user.is_active or not user.is_staff:
             raise forms.ValidationError(
                 self.error_messages['invalid_login'],
                 code='invalid_login',
                 params={'username': self.username_field.verbose_name}
             )
 }}}

 So I suggest to change it like

 {{{
 error_messages = {
         ...
         'inactive': _("This account is inactive."),
     }

     ...
     def confirm_login_allowed(self, user):
         if not user.is_active:
             raise forms.ValidationError(
                 self.error_messages['inactive'],
                 code='inactive',
             )

         if not user.is_staff:
             raise forms.ValidationError(
                 self.error_messages['invalid_login'],
                 code='invalid_login',
                 params = {'username': self.username_field.verbose_name},
             )
     ....
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28751#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.6c74c0357a8c101810793ec5777a35ab%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to