Ticket #8906: 8906_auth_script_prefix.diff

File 8906_auth_script_prefix.diff, 3.4 KB (added by lygaret, 16 years ago)

really basic patch for script_prefix aware @login_required

  • django/contrib/auth/views.py

     
    44from django.contrib.auth.forms import AuthenticationForm
    55from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm, PasswordChangeForm
    66from django.contrib.auth.tokens import default_token_generator
    7 from django.core.urlresolvers import reverse
     7from django.core.urlresolvers import reverse, get_script_prefix
    88from django.shortcuts import render_to_response, get_object_or_404
    99from django.contrib.sites.models import Site, RequestSite
    1010from django.http import HttpResponseRedirect, Http404
     
    2222        if form.is_valid():
    2323            # Light security check -- make sure redirect_to isn't garbage.
    2424            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
    25                 redirect_to = settings.LOGIN_REDIRECT_URL
     25                redirect_to = get_script_prefix() + settings.LOGIN_REDIRECT_URL
    2626            from django.contrib.auth import login
    2727            login(request, form.get_user())
    2828            if request.session.test_cookie_worked():
     
    5555def logout_then_login(request, login_url=None):
    5656    "Logs out the user if he is logged in. Then redirects to the log-in page."
    5757    if not login_url:
    58         login_url = settings.LOGIN_URL
     58        login_url = get_script_prefix() + settings.LOGIN_URL
    5959    return logout(request, login_url)
    6060
    6161def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
    6262    "Redirects the user to the login page, passing the given 'next' page"
    6363    if not login_url:
    64         login_url = settings.LOGIN_URL
     64        login_url = get_script_prefix() + settings.LOGIN_URL
    6565    return HttpResponseRedirect('%s?%s=%s' % (login_url, urlquote(redirect_field_name), urlquote(next)))
    6666
    6767# 4 views for password reset:
     
    135135
    136136def password_reset_complete(request, template_name='registration/password_reset_complete.html'):
    137137    return render_to_response(template_name, context_instance=RequestContext(request,
    138                                                                              {'login_url': settings.LOGIN_URL}))
     138                                                                             {'login_url': get_script_prefix() + settings.LOGIN_URL}))
    139139
    140140def password_change(request, template_name='registration/password_change_form.html',
    141141                    post_change_redirect=None):
  • django/contrib/auth/decorators.py

     
    33except ImportError:
    44    from django.utils.functional import update_wrapper  # Python 2.3, 2.4 fallback.
    55
     6from django.core.urlresolvers import get_script_prefix
    67from django.contrib.auth import REDIRECT_FIELD_NAME
    78from django.http import HttpResponseRedirect
    89from django.utils.http import urlquote
     
    5152    def __init__(self, view_func, test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
    5253        if not login_url:
    5354            from django.conf import settings
    54             login_url = settings.LOGIN_URL
     55            login_url = get_script_prefix() + settings.LOGIN_URL
    5556        self.view_func = view_func
    5657        self.test_func = test_func
    5758        self.login_url = login_url
Back to Top