diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index dc869ebd02..521caedbd0 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -312,6 +312,12 @@ BANNED_IPS = () AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',) +LOGIN_URL = '/accounts/login/' + +LOGOUT_URL = '/accounts/logout/' + +LOGIN_REDIRECT_URL = '/accounts/profile/' + ########### # TESTING # ########### diff --git a/django/contrib/auth/__init__.py b/django/contrib/auth/__init__.py index dd3b8152e6..8c92732f44 100644 --- a/django/contrib/auth/__init__.py +++ b/django/contrib/auth/__init__.py @@ -2,7 +2,6 @@ from django.core.exceptions import ImproperlyConfigured SESSION_KEY = '_auth_user_id' BACKEND_SESSION_KEY = '_auth_user_backend' -LOGIN_URL = '/accounts/login/' REDIRECT_FIELD_NAME = 'next' def load_backend(path): diff --git a/django/contrib/auth/decorators.py b/django/contrib/auth/decorators.py index 37e948f8fe..2fb4a6f510 100644 --- a/django/contrib/auth/decorators.py +++ b/django/contrib/auth/decorators.py @@ -1,13 +1,16 @@ -from django.contrib.auth import LOGIN_URL, REDIRECT_FIELD_NAME +from django.contrib.auth import REDIRECT_FIELD_NAME from django.http import HttpResponseRedirect from urllib import quote -def user_passes_test(test_func, login_url=LOGIN_URL): +def user_passes_test(test_func, login_url=None): """ Decorator for views that checks that the user passes the given test, redirecting to the log-in page if necessary. The test should be a callable that takes the user object and returns True if the user passes. """ + if not login_url: + from django.conf import settings + login_url = settings.LOGIN_URL def _dec(view_func): def _checklogin(request, *args, **kwargs): if test_func(request.user): @@ -27,7 +30,7 @@ login_required.__doc__ = ( """ ) -def permission_required(perm, login_url=LOGIN_URL): +def permission_required(perm, login_url=None): """ Decorator for views that checks whether a user has a particular permission enabled, redirecting to the log-in page if necessary. diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py index fda17b91fb..77350b9a8f 100644 --- a/django/contrib/auth/views.py +++ b/django/contrib/auth/views.py @@ -6,7 +6,7 @@ from django.template import RequestContext from django.contrib.sites.models import Site from django.http import HttpResponseRedirect from django.contrib.auth.decorators import login_required -from django.contrib.auth import LOGIN_URL, REDIRECT_FIELD_NAME +from django.contrib.auth import REDIRECT_FIELD_NAME def login(request, template_name='registration/login.html'): "Displays the login form and handles the login action." @@ -17,7 +17,8 @@ def login(request, template_name='registration/login.html'): if not errors: # Light security check -- make sure redirect_to isn't garbage. if not redirect_to or '://' in redirect_to or ' ' in redirect_to: - redirect_to = '/accounts/profile/' + from django.conf import settings + redirect_to = settings.LOGIN_REDIRECT_URL from django.contrib.auth import login login(request, manipulator.get_user()) request.session.delete_test_cookie() @@ -41,12 +42,18 @@ def logout(request, next_page=None, template_name='registration/logged_out.html' # Redirect to this page until the session has been cleared. return HttpResponseRedirect(next_page or request.path) -def logout_then_login(request, login_url=LOGIN_URL): +def logout_then_login(request, login_url=None): "Logs out the user if he is logged in. Then redirects to the log-in page." + if not login_url: + from django.conf import settings + login_url = settings.LOGIN_URL return logout(request, login_url) -def redirect_to_login(next, login_url=LOGIN_URL): +def redirect_to_login(next, login_url=None): "Redirects the user to the login page, passing the given 'next' page" + if not login_url: + from django.conf import settings + login_url = settings.LOGIN_URL return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next)) def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', diff --git a/django/contrib/comments/templates/comments/form.html b/django/contrib/comments/templates/comments/form.html index c5aa7686a3..11eaa8d00d 100644 --- a/django/contrib/comments/templates/comments/form.html +++ b/django/contrib/comments/templates/comments/form.html @@ -3,7 +3,7 @@