Ticket #9168: authentication_form.diff

File authentication_form.diff, 2.2 KB (added by SmileyChris, 7 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

     
    717717
    718718        {% endblock %}
    719719
     720    If you are using an `alternate authentication source`_ you can pass a
     721    custom authentication form to the login view via the
     722    ``authentication_form`` parameter. This form must accept a ``request``
     723    keyword argument in its ``__init__`` method, and provide a ``get_user``
     724    argument which returns the authenticated user object (this method is only
     725    ever called after successful form validation).
     726
    720727    .. _forms documentation: ../forms/
    721728    .. _site framework docs: ../sites/
     729    .. _alternate authentication source: #other-authentication-sources
    722730
    723731Other built-in views
    724732--------------------
Back to Top