Ticket #9168: authentication_form.2.diff
File authentication_form.2.diff, 2.7 KB (added by , 16 years ago) |
---|
-
django/contrib/auth/views.py
14 14 from django.contrib.auth.models import User 15 15 from django.views.decorators.cache import never_cache 16 16 17 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME): 17 def login(request, template_name='registration/login.html', 18 redirect_field_name=REDIRECT_FIELD_NAME, 19 authentication_form=AuthenticationForm): 18 20 "Displays the login form and handles the login action." 19 21 redirect_to = request.REQUEST.get(redirect_field_name, '') 20 22 if request.method == "POST": 21 form = AuthenticationForm(data=request.POST)23 form = authentication_form(data=request.POST) 22 24 if form.is_valid(): 23 25 # Light security check -- make sure redirect_to isn't garbage. 24 26 if not redirect_to or '//' in redirect_to or ' ' in redirect_to: … … 29 31 request.session.delete_test_cookie() 30 32 return HttpResponseRedirect(redirect_to) 31 33 else: 32 form = AuthenticationForm(request)34 form = authentication_form(request) 33 35 request.session.set_test_cookie() 34 36 if Site._meta.installed: 35 37 current_site = Site.objects.get_current() -
docs/topics/auth.txt
523 523 :func:`~django.contrib.auth.authenticate()` 524 524 sets an attribute on the :class:`~django.contrib.auth.models.User` noting 525 525 which authentication backend successfully authenticated that user (see 526 the `backends documentation`_ for details), and this information is527 neededlater during the login process.526 :ref:`authentication-backends` for details), and this information is needed 527 later during the login process. 528 528 529 .. _backends documentation: #other-authentication-sources530 531 529 Manually checking a user's password 532 530 ----------------------------------- 533 531 … … 717 715 718 716 {% endblock %} 719 717 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 720 727 .. _forms documentation: ../forms/ 721 728 .. _site framework docs: ../sites/ 722 729