Code

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

File django-contrib-auth-absolute-login-url.patch, 3.0 KB (added by arikon, 5 years ago)

django.contrib.auth absolute LOGIN_URL patch ver. 1

  • django/conf/global_settings.py

     
    374374 
    375375LOGIN_REDIRECT_URL = '/accounts/profile/' 
    376376 
     377REDIRECT_FIELD_NAME = 'next' 
     378 
    377379# The number of days a password reset link is valid for 
    378380PASSWORD_RESET_TIMEOUT_DAYS = 3 
    379381 
  • django/contrib/auth/views.py

     
    6969    "Redirects the user to the login page, passing the given 'next' page" 
    7070    if not login_url: 
    7171        login_url = settings.LOGIN_URL 
    72     return HttpResponseRedirect('%s?%s=%s' % (login_url, urlquote(redirect_field_name), urlquote(next))) 
     72    if '?' in login_url: 
     73        login_url += '&' 
     74    else: 
     75        login_url += '?' 
     76    return HttpResponseRedirect('%s%s=%s' % (login_url, urlquote(redirect_field_name), urlquote(next))) 
    7377 
    7478# 4 views for password reset: 
    7579# - password_reset sends the mail 
  • django/contrib/auth/__init__.py

     
    11import datetime 
     2from django.conf import settings 
    23from django.core.exceptions import ImproperlyConfigured 
    34from django.utils.importlib import import_module 
    45 
    56SESSION_KEY = '_auth_user_id' 
    67BACKEND_SESSION_KEY = '_auth_user_backend' 
    7 REDIRECT_FIELD_NAME = 'next' 
     8REDIRECT_FIELD_NAME = settings.REDIRECT_FIELD_NAME 
    89 
    910def load_backend(path): 
    1011    i = path.rfind('.') 
     
    2223    return cls() 
    2324 
    2425def get_backends(): 
    25     from django.conf import settings 
    2626    backends = [] 
    2727    for backend_path in settings.AUTHENTICATION_BACKENDS: 
    2828        backends.append(load_backend(backend_path)) 
  • django/contrib/auth/decorators.py

     
     1import urlparse 
    12try: 
    23    from functools import update_wrapper 
    34except ImportError: 
     
    7677    def __call__(self, request, *args, **kwargs): 
    7778        if self.test_func(request.user): 
    7879            return self.view_func(request, *args, **kwargs) 
    79         path = urlquote(request.get_full_path()) 
    80         tup = self.login_url, self.redirect_field_name, path 
    81         return HttpResponseRedirect('%s?%s=%s' % tup) 
     80        login_url = list(urlparse.urlparse(self.login_url)) 
     81        if login_url[1].lower() == request.META['SERVER_NAME'].lower(): 
     82            path = urlquote(request.get_full_path()) 
     83            login_url[1] = '' 
     84        else: 
     85            path = urlquote(request.build_absolute_uri()) 
     86        if login_url[4]: 
     87            login_url[4] += '&' 
     88        login_url[4] += '%s=%s' % (self.redirect_field_name, path) 
     89        return HttpResponseRedirect(urlparse.urlunparse(login_url))