Ticket #12103: 12103_with_documentation.diff

File 12103_with_documentation.diff, 1.8 KB (added by ejucovy, 6 years ago)
  • django/contrib/auth/forms.py

     
    5959    username = forms.CharField(label=_("Username"), max_length=30)
    6060    password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
    6161
     62    allow_inactive_logins = False
     63
    6264    def __init__(self, request=None, *args, **kwargs):
    6365        """
    6466        If request is passed in, the form will validate that cookies are
     
    7880            self.user_cache = authenticate(username=username, password=password)
    7981            if self.user_cache is None:
    8082                raise forms.ValidationError(_("Please enter a correct username and password. Note that both fields are case-sensitive."))
    81             elif not self.user_cache.is_active:
     83            elif not self.allow_inactive_logins and not self.user_cache.is_active:
    8284                raise forms.ValidationError(_("This account is inactive."))
    8385
    8486        # TODO: determine whether this should move to its own method.
  • docs/topics/auth.txt

     
    970970
    971971    A form for logging a user in.
    972972
     973    The ``AuthenticationForm`` rejects users whose ``is_active`` flag is set to ``False``.
     974    You may override this behavior and allow inactive users to log in. Do this with a
     975    custom form that subclasses ``AuthenticationForm`` like
     976
     977    .. code-block:: python
     978
     979        class AuthenticationFormWithInactiveUsersOkay(AuthenticationForm):
     980            allow_inactive_logins = True
     981
    973982.. class:: PasswordChangeForm
    974983
    975984    A form for allowing a user to change their password.
Back to Top