Ticket #9168: authentication_form.2.diff

File authentication_form.2.diff, 2.7 KB (added by Chris Beaven, 16 years ago)
  • django/contrib/auth/views.py

     
    1414from django.contrib.auth.models import User
    1515from django.views.decorators.cache import never_cache
    1616
    17 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME):
     17def login(request, template_name='registration/login.html',
     18          redirect_field_name=REDIRECT_FIELD_NAME,
     19          authentication_form=AuthenticationForm):
    1820    "Displays the login form and handles the login action."
    1921    redirect_to = request.REQUEST.get(redirect_field_name, '')
    2022    if request.method == "POST":
    21         form = AuthenticationForm(data=request.POST)
     23        form = authentication_form(data=request.POST)
    2224        if form.is_valid():
    2325            # Light security check -- make sure redirect_to isn't garbage.
    2426            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
     
    2931                request.session.delete_test_cookie()
    3032            return HttpResponseRedirect(redirect_to)
    3133    else:
    32         form = AuthenticationForm(request)
     34        form = authentication_form(request)
    3335    request.session.set_test_cookie()
    3436    if Site._meta.installed:
    3537        current_site = Site.objects.get_current()
  • docs/topics/auth.txt

     
    523523    :func:`~django.contrib.auth.authenticate()`
    524524    sets an attribute on the :class:`~django.contrib.auth.models.User` noting
    525525    which authentication backend successfully authenticated that user (see
    526     the `backends documentation`_ for details), and this information is
    527     needed later during the login process.
     526    :ref:`authentication-backends` for details), and this information is needed
     527    later during the login process.
    528528
    529 .. _backends documentation: #other-authentication-sources
    530 
    531529Manually checking a user's password
    532530-----------------------------------
    533531
     
    717715
    718716        {% endblock %}
    719717
     718    **New in Django development version**
     719
     720    If you are using alternate authentication (see
     721    :ref:`authentication-backends`) you can pass a custom authentication form
     722    to the login view via the ``authentication_form`` parameter. This form must
     723    accept a ``request`` keyword argument in its ``__init__`` method, and
     724    provide a ``get_user`` argument which returns the authenticated user object
     725    (this method is only ever called after successful form validation).
     726
    720727    .. _forms documentation: ../forms/
    721728    .. _site framework docs: ../sites/
    722729
Back to Top