Code

Ticket #3185: 3185.diff

File 3185.diff, 4.3 KB (added by Gary Wilson <gary.wilson@…>, 7 years ago)

code and docs in one patch

Line 
1=== modified file 'django/contrib/auth/__init__.py'
2--- django/contrib/auth/__init__.py     2006-12-19 04:35:09 +0000
3+++ django/contrib/auth/__init__.py     2007-01-18 01:42:17 +0000
4@@ -1,8 +1,10 @@
5+from django.conf import settings
6 from django.core.exceptions import ImproperlyConfigured
7 
8 SESSION_KEY = '_auth_user_id'
9 BACKEND_SESSION_KEY = '_auth_user_backend'
10-LOGIN_URL = '/accounts/login/'
11+LOGIN_URL = getattr(settings, 'LOGIN_URL', '/accounts/login/')
12+ACCOUNT_URL = getattr(settings, 'ACCOUNT_URL', '/accounts/profile/')
13 REDIRECT_FIELD_NAME = 'next'
14 
15 def load_backend(path):
16
17=== modified file 'django/contrib/auth/views.py'
18--- django/contrib/auth/views.py        2006-12-19 04:35:09 +0000
19+++ django/contrib/auth/views.py        2007-01-18 01:43:37 +0000
20@@ -6,7 +6,7 @@
21 from django.contrib.sites.models import Site
22 from django.http import HttpResponseRedirect
23 from django.contrib.auth.decorators import login_required
24-from django.contrib.auth import LOGIN_URL, REDIRECT_FIELD_NAME
25+from django.contrib.auth import LOGIN_URL, ACCOUNT_URL, REDIRECT_FIELD_NAME
26 
27 def login(request, template_name='registration/login.html'):
28     "Displays the login form and handles the login action."
29@@ -17,7 +17,7 @@
30         if not errors:
31             # Light security check -- make sure redirect_to isn't garbage.
32             if not redirect_to or '://' in redirect_to or ' ' in redirect_to:
33-                redirect_to = '/accounts/profile/'
34+                redirect_to = ACCOUNT_URL
35             from django.contrib.auth import login
36             login(request, manipulator.get_user())
37             request.session.delete_test_cookie()
38
39=== modified file 'docs/authentication.txt'
40--- docs/authentication.txt     2006-12-19 04:35:09 +0000
41+++ docs/authentication.txt     2007-01-19 17:27:23 +0000
42@@ -377,14 +377,15 @@
43 
44 ``login_required`` does the following:
45 
46-    * If the user isn't logged in, redirect to ``/accounts/login/``, passing
47-      the current absolute URL in the query string as ``next``. For example:
48+    * If the user isn't logged in, redirect to ``"settings.LOGIN_URL"``
49+      (``"/accounts/login/"`` by default), passing the current absolute URL
50+      in the query string as ``next``. For example:
51       ``/accounts/login/?next=/polls/3/``.
52     * If the user is logged in, execute the view normally. The view code is
53       free to assume the user is logged in.
54 
55-Note that you'll need to map the appropriate Django view to ``/accounts/login/``.
56-To do this, add the following line to your URLconf::
57+Note that you'll need to map the appropriate Django view to ``"settings.LOGIN_URL"``.
58+For example, using the defaults, add the following line to your URLconf::
59 
60     (r'^accounts/login/$', 'django.contrib.auth.views.login'),
61 
62@@ -395,8 +396,8 @@
63 
64     * If called via ``POST``, it tries to log the user in. If login is
65       successful, the view redirects to the URL specified in ``next``. If
66-      ``next`` isn't provided, it redirects to ``/accounts/profile/`` (which is
67-      currently hard-coded). If login isn't successful, it redisplays the login
68+      ``next`` isn't provided, it redirects to ``"settings.ACCOUNT_URL"`` which
69+      defaults to ``/accounts/profile/``. If login isn't successful, it redisplays the login
70       form.
71 
72 It's your responsibility to provide the login form in a template called
73
74=== modified file 'docs/settings.txt'
75--- docs/settings.txt   2007-01-03 23:43:22 +0000
76+++ docs/settings.txt   2007-01-19 17:27:23 +0000
77@@ -166,6 +166,15 @@
78         'news.Story': lambda o: "/stories/%s/%s/" % (o.pub_year, o.slug),
79     }
80 
81+ACCOUNT_URL
82+-------------
83+
84+Default: ``'/accounts/profile/'``
85+
86+The URL where requests are redirected after login when the ``"contrib.auth.login"`` view
87+gets no ``next`` parameter.
88+i.e.: When the `@login_required`_ decorator is called
89+
90 ADMIN_FOR
91 ---------
92 
93@@ -533,6 +542,14 @@
94 you'll have to remember to wrap the languages in the *real* ``gettext()`` in
95 any code that uses ``LANGUAGES`` at runtime.
96 
97+LOGIN_URL
98+-------------
99+
100+Default: ``'/accounts/login/'``
101+
102+The URL where requests are redirected for login, specially when using the
103+`@login_required`_ decorator.
104+
105 MANAGERS
106 --------
107 
108@@ -967,3 +984,5 @@
109 
110 It boils down to this: Use exactly one of either ``configure()`` or
111 ``DJANGO_SETTINGS_MODULE``. Not both, and not neither.
112+
113+.. _@login_required: http://www.djangoproject.com/documentation/authentication/#the-login-required-decorator
114