Ticket #10342: r9897-login-form-override.patch

File r9897-login-form-override.patch, 1.7 KB (added by steph, 6 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):
    18     "Displays the login form and handles the login action."
     17def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, form_class=AuthenticationForm):
     18    """
     19    Displays the login form and handles the login action.
     20   
     21    **Optional arguments**
     22       
     23        ``template_name``
     24            A custom template to use.
     25       
     26        ``redirect_field_name``
     27            A custom field name for redirect url.
     28           
     29        ``form_class``
     30            The form class to use for login.
     31   
     32    """
     33   
    1934    redirect_to = request.REQUEST.get(redirect_field_name, '')
    2035    if request.method == "POST":
    21         form = AuthenticationForm(data=request.POST)
     36        form = form_class(data=request.POST)
    2237        if form.is_valid():
    2338            # Light security check -- make sure redirect_to isn't garbage.
    2439            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
     
    2944                request.session.delete_test_cookie()
    3045            return HttpResponseRedirect(redirect_to)
    3146    else:
    32         form = AuthenticationForm(request)
     47        form = form_class(request)
    3348    request.session.set_test_cookie()
    3449    if Site._meta.installed:
    3550        current_site = Site.objects.get_current()
Back to Top