Ticket #8274: 8274.auth_forms.diff

File 8274.auth_forms.diff, 2.3 KB (added by Julien Phalip, 16 years ago)
  • django/django/contrib/auth/views.py

     
    1616from django.contrib.auth.models import User
    1717import re
    1818
    19 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME):
     19def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=AuthenticationForm):
    2020    "Displays the login form and handles the login action."
    2121    redirect_to = request.REQUEST.get(redirect_field_name, '')
    2222    if request.method == "POST":
    23         form = AuthenticationForm(data=request.POST)
     23        form = authentication_form(data=request.POST)
    2424        if form.is_valid():
    2525            # Light security check -- make sure redirect_to isn't garbage.
    2626            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
     
    3232                request.session.delete_test_cookie()
    3333            return HttpResponseRedirect(redirect_to)
    3434    else:
    35         form = AuthenticationForm(request)
     35        form = authentication_form(request)
    3636    request.session.set_test_cookie()
    3737    if Site._meta.installed:
    3838        current_site = Site.objects.get_current()
     
    135135    return render_to_response(template_name, context_instance=RequestContext(request,
    136136                                                                             {'login_url': settings.LOGIN_URL}))
    137137
    138 def password_change(request, template_name='registration/password_change_form.html'):
     138def password_change(request, template_name='registration/password_change_form.html', password_change_form=PasswordChangeForm):
    139139    if request.method == "POST":
    140         form = PasswordChangeForm(request.user, request.POST)
     140        form = password_change_form(request.user, request.POST)
    141141        if form.is_valid():
    142142            form.save()
    143143            return HttpResponseRedirect(reverse('django.contrib.auth.views.password_change_done'))
    144144    else:
    145         form = PasswordChangeForm(request.user)
     145        form = password_change_form(request.user)
    146146    return render_to_response(template_name, {
    147147        'form': form,
    148148    }, context_instance=RequestContext(request))
Back to Top