Ticket #9168: authentication_form.diff
File authentication_form.diff, 2.2 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
717 717 718 718 {% endblock %} 719 719 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 720 727 .. _forms documentation: ../forms/ 721 728 .. _site framework docs: ../sites/ 729 .. _alternate authentication source: #other-authentication-sources 722 730 723 731 Other built-in views 724 732 --------------------