Ticket #11025: django-contrib-auth-absolute-login-url.2.patch

File django-contrib-auth-absolute-login-url.2.patch, 3.4 KB (added by thasonic, 15 years ago)
  • django/conf/global_settings.py

     
    467467
    468468LOGIN_REDIRECT_URL = '/accounts/profile/'
    469469
     470REDIRECT_FIELD_NAME = 'next'
     471
    470472# The number of days a password reset link is valid for
    471473PASSWORD_RESET_TIMEOUT_DAYS = 3
    472474
  • django/contrib/auth/views.py

     
    9292    "Redirects the user to the login page, passing the given 'next' page"
    9393    if not login_url:
    9494        login_url = settings.LOGIN_URL
    95     return HttpResponseRedirect('%s?%s=%s' % (login_url, urlquote(redirect_field_name), urlquote(next)))
     95    if '?' in login_url:
     96        login_url += '&'
     97    else:
     98        login_url += '?'
     99    return HttpResponseRedirect('%s%s=%s' % (login_url, urlquote(redirect_field_name), urlquote(next)))
    96100
    97101# 4 views for password reset:
    98102# - password_reset sends the mail
  • django/contrib/auth/__init__.py

     
    11import datetime
    22from warnings import warn
     3from django.conf import settings
    34from django.core.exceptions import ImproperlyConfigured
    45from django.utils.importlib import import_module
    56
    67SESSION_KEY = '_auth_user_id'
    78BACKEND_SESSION_KEY = '_auth_user_backend'
    8 REDIRECT_FIELD_NAME = 'next'
     9REDIRECT_FIELD_NAME = settings.REDIRECT_FIELD_NAME
    910
    1011def load_backend(path):
    1112    i = path.rfind('.')
     
    3536    return cls()
    3637
    3738def get_backends():
    38     from django.conf import settings
    3939    backends = []
    4040    for backend_path in settings.AUTHENTICATION_BACKENDS:
    4141        backends.append(load_backend(backend_path))
  • django/contrib/auth/decorators.py

     
     1import urlparse
     2
    13try:
    24    from functools import update_wrapper, wraps
    35except ImportError:
     
    2224        def _wrapped_view(request, *args, **kwargs):
    2325            if test_func(request.user):
    2426                return view_func(request, *args, **kwargs)
    25             path = urlquote(request.get_full_path())
    26             tup = login_url, redirect_field_name, path
    27             return HttpResponseRedirect('%s?%s=%s' % tup)
     27            url = urlparse.urlsplit(login_url)
     28            scheme, hostname = url.scheme, url.netloc
     29            if hostname.lower() == request.META['SERVER_NAME'].lower():
     30                retpath = urlquote(request.get_full_path())
     31                hostname = ''
     32                scheme = ''
     33            else:
     34                retpath = urlquote(request.build_absolute_uri())
     35            query = url.query
     36            if query:
     37                query += '&'
     38            query += '%s=%s' % (redirect_field_name, retpath)
     39            return HttpResponseRedirect(urlparse.urlunsplit(urlparse.SplitResult(
     40                scheme = scheme,
     41                netloc = hostname,
     42                path = url.path,
     43                query = query,
     44                fragment = ''
     45            )))
    2846        return wraps(view_func)(_wrapped_view)
    2947    return decorator
    3048
Back to Top