Corrected some indentation in docs/topics/auth/default.txt.
This commit is contained in:
parent
9560dac3c0
commit
34f4fd7024
|
@ -1099,12 +1099,12 @@ patterns.
|
|||
* ``template_name``: The full name of a template to display the view.
|
||||
Defaults to :file:`registration/password_reset_complete.html`.
|
||||
|
||||
* ``current_app``: A hint indicating which application contains the current
|
||||
view. See the :ref:`namespaced URL resolution strategy
|
||||
<topics-http-reversing-url-namespaces>` for more information.
|
||||
* ``current_app``: A hint indicating which application contains the current
|
||||
view. See the :ref:`namespaced URL resolution strategy
|
||||
<topics-http-reversing-url-namespaces>` for more information.
|
||||
|
||||
* ``extra_context``: A dictionary of context data that will be added to the
|
||||
default context data passed to the template.
|
||||
* ``extra_context``: A dictionary of context data that will be added to the
|
||||
default context data passed to the template.
|
||||
|
||||
Helper functions
|
||||
----------------
|
||||
|
@ -1164,37 +1164,37 @@ provides several built-in forms located in :mod:`django.contrib.auth.forms`:
|
|||
|
||||
.. method:: confirm_login_allowed(user)
|
||||
|
||||
.. versionadded:: 1.7
|
||||
.. versionadded:: 1.7
|
||||
|
||||
By default, ``AuthenticationForm`` rejects users whose ``is_active`` flag
|
||||
is set to ``False``. You may override this behavior with a custom policy to
|
||||
determine which users can log in. Do this with a custom form that subclasses
|
||||
``AuthenticationForm`` and overrides the ``confirm_login_allowed`` method.
|
||||
This method should raise a :exc:`~django.core.exceptions.ValidationError`
|
||||
if the given user may not log in.
|
||||
By default, ``AuthenticationForm`` rejects users whose ``is_active`` flag
|
||||
is set to ``False``. You may override this behavior with a custom policy to
|
||||
determine which users can log in. Do this with a custom form that subclasses
|
||||
``AuthenticationForm`` and overrides the ``confirm_login_allowed`` method.
|
||||
This method should raise a :exc:`~django.core.exceptions.ValidationError`
|
||||
if the given user may not log in.
|
||||
|
||||
For example, to allow all users to log in, regardless of "active" status::
|
||||
For example, to allow all users to log in, regardless of "active" status::
|
||||
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
|
||||
class AuthenticationFormWithInactiveUsersOkay(AuthenticationForm):
|
||||
def confirm_login_allowed(self, user):
|
||||
pass
|
||||
class AuthenticationFormWithInactiveUsersOkay(AuthenticationForm):
|
||||
def confirm_login_allowed(self, user):
|
||||
pass
|
||||
|
||||
Or to allow only some active users to log in::
|
||||
Or to allow only some active users to log in::
|
||||
|
||||
class PickyAuthenticationForm(AuthenticationForm):
|
||||
def confirm_login_allowed(self, user):
|
||||
if not user.is_active:
|
||||
raise forms.ValidationError(
|
||||
_("This account is inactive."),
|
||||
code='inactive',
|
||||
)
|
||||
if user.username.startswith('b'):
|
||||
raise forms.ValidationError(
|
||||
_("Sorry, accounts starting with 'b' aren't welcome here."),
|
||||
code='no_b_users',
|
||||
)
|
||||
class PickyAuthenticationForm(AuthenticationForm):
|
||||
def confirm_login_allowed(self, user):
|
||||
if not user.is_active:
|
||||
raise forms.ValidationError(
|
||||
_("This account is inactive."),
|
||||
code='inactive',
|
||||
)
|
||||
if user.username.startswith('b'):
|
||||
raise forms.ValidationError(
|
||||
_("Sorry, accounts starting with 'b' aren't welcome here."),
|
||||
code='no_b_users',
|
||||
)
|
||||
|
||||
.. class:: PasswordChangeForm
|
||||
|
||||
|
|
Loading…
Reference in New Issue