Changeset 5072
- Timestamp:
- 04/25/07 03:49:57 (1 year ago)
- Files:
-
- django/trunk/django/conf/global_settings.py (modified) (1 diff)
- django/trunk/django/contrib/auth/decorators.py (modified) (3 diffs)
- django/trunk/django/contrib/auth/__init__.py (modified) (1 diff)
- django/trunk/django/contrib/auth/views.py (modified) (3 diffs)
- django/trunk/django/contrib/comments/templates/comments/form.html (modified) (1 diff)
- django/trunk/django/contrib/comments/templatetags/comments.py (modified) (2 diffs)
- django/trunk/docs/authentication.txt (modified) (6 diffs)
- django/trunk/docs/settings.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/conf/global_settings.py
r4975 r5072 313 313 AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',) 314 314 315 LOGIN_URL = '/accounts/login/' 316 317 LOGOUT_URL = '/accounts/logout/' 318 319 LOGIN_REDIRECT_URL = '/accounts/profile/' 320 315 321 ########### 316 322 # TESTING # django/trunk/django/contrib/auth/decorators.py
r4265 r5072 1 from django.contrib.auth import LOGIN_URL,REDIRECT_FIELD_NAME1 from django.contrib.auth import REDIRECT_FIELD_NAME 2 2 from django.http import HttpResponseRedirect 3 3 from urllib import quote 4 4 5 def user_passes_test(test_func, login_url= LOGIN_URL):5 def user_passes_test(test_func, login_url=None): 6 6 """ 7 7 Decorator for views that checks that the user passes the given test, … … 9 9 that takes the user object and returns True if the user passes. 10 10 """ 11 if not login_url: 12 from django.conf import settings 13 login_url = settings.LOGIN_URL 11 14 def _dec(view_func): 12 15 def _checklogin(request, *args, **kwargs): … … 28 31 ) 29 32 30 def permission_required(perm, login_url= LOGIN_URL):33 def permission_required(perm, login_url=None): 31 34 """ 32 35 Decorator for views that checks whether a user has a particular permission django/trunk/django/contrib/auth/__init__.py
r4265 r5072 3 3 SESSION_KEY = '_auth_user_id' 4 4 BACKEND_SESSION_KEY = '_auth_user_backend' 5 LOGIN_URL = '/accounts/login/'6 5 REDIRECT_FIELD_NAME = 'next' 7 6 django/trunk/django/contrib/auth/views.py
r4486 r5072 7 7 from django.http import HttpResponseRedirect 8 8 from django.contrib.auth.decorators import login_required 9 from django.contrib.auth import LOGIN_URL,REDIRECT_FIELD_NAME9 from django.contrib.auth import REDIRECT_FIELD_NAME 10 10 11 11 def login(request, template_name='registration/login.html'): … … 18 18 # Light security check -- make sure redirect_to isn't garbage. 19 19 if not redirect_to or '://' in redirect_to or ' ' in redirect_to: 20 redirect_to = '/accounts/profile/' 20 from django.conf import settings 21 redirect_to = settings.LOGIN_REDIRECT_URL 21 22 from django.contrib.auth import login 22 23 login(request, manipulator.get_user()) … … 42 43 return HttpResponseRedirect(next_page or request.path) 43 44 44 def logout_then_login(request, login_url= LOGIN_URL):45 def logout_then_login(request, login_url=None): 45 46 "Logs out the user if he is logged in. Then redirects to the log-in page." 47 if not login_url: 48 from django.conf import settings 49 login_url = settings.LOGIN_URL 46 50 return logout(request, login_url) 47 51 48 def redirect_to_login(next, login_url= LOGIN_URL):52 def redirect_to_login(next, login_url=None): 49 53 "Redirects the user to the login page, passing the given 'next' page" 54 if not login_url: 55 from django.conf import settings 56 login_url = settings.LOGIN_URL 50 57 return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next)) 51 58 django/trunk/django/contrib/comments/templates/comments/form.html
r3360 r5072 4 4 5 5 {% if user.is_authenticated %} 6 <p>{% trans "Username:" %} <strong>{{ user.username }}</strong> (<a href=" /accounts/logout/">{% trans "Log out" %}</a>)</p>6 <p>{% trans "Username:" %} <strong>{{ user.username }}</strong> (<a href="{{ logout_url }}">{% trans "Log out" %}</a>)</p> 7 7 {% else %} 8 8 <p><label for="id_username">{% trans "Username:" %}</label> <input type="text" name="username" id="id_username" /><br />{% trans "Password:" %} <input type="password" name="password" id="id_password" /> (<a href="/accounts/password_reset/">{% trans "Forgotten your password?" %}</a>)</p> django/trunk/django/contrib/comments/templatetags/comments.py
r3360 r5072 26 26 27 27 def render(self, context): 28 from django.conf import settings 28 29 from django.utils.text import normalize_newlines 29 30 import base64 … … 65 66 context['rating_range'], context['rating_choices'] = Comment.objects.get_rating_options(self.rating_options) 66 67 context['hash'] = Comment.objects.get_security_hash(context['options'], context['photo_options'], context['rating_options'], context['target']) 68 context['logout_url'] = settings.LOGOUT_URL 67 69 default_form = loader.get_template(COMMENT_FORM) 68 70 output = default_form.render(context) django/trunk/docs/authentication.txt
r5064 r5072 388 388 ``login_required`` does the following: 389 389 390 * If the user isn't logged in, redirect to ``/accounts/login/``, passing 391 the current absolute URL in the query string as ``next``. For example: 390 * If the user isn't logged in, redirect to ``settings.LOGIN_URL`` 391 (``/accounts/login/`` by default), passing the current absolute URL 392 in the query string as ``next``. For example: 392 393 ``/accounts/login/?next=/polls/3/``. 393 394 * If the user is logged in, execute the view normally. The view code is 394 395 free to assume the user is logged in. 395 396 396 Note that you'll need to map the appropriate Django view to `` /accounts/login/``.397 To do this, add the following line to your URLconf::397 Note that you'll need to map the appropriate Django view to ``settings.LOGIN_URL``. 398 For example, using the defaults, add the following line to your URLconf:: 398 399 399 400 (r'^accounts/login/$', 'django.contrib.auth.views.login'), … … 406 407 * If called via ``POST``, it tries to log the user in. If login is 407 408 successful, the view redirects to the URL specified in ``next``. If 408 ``next`` isn't provided, it redirects to `` /accounts/profile/`` (which is409 currently hard-coded). If login isn't successful, it redisplays the login410 form.409 ``next`` isn't provided, it redirects to ``settings.LOGIN_REDIRECT_URL`` 410 (which defaults to ``/accounts/profile/``). If login isn't successful, 411 it redisplays the login form. 411 412 412 413 It's your responsibility to provide the login form in a template called … … 488 489 489 490 * ``login_url``: The URL of the login page to redirect to. This 490 will default to `` /accounts/login/`` if not supplied.491 will default to ``settings.LOGIN_URL`` if not supplied. 491 492 492 493 ``django.contrib.auth.views.password_change`` … … 570 571 571 572 * ``login_url``: The URL of the login page to redirect to. This 572 will default to `` /accounts/login/`` if not supplied.573 will default to ``settings.LOGIN_URL`` if not supplied. 573 574 574 575 Built-in manipulators … … 637 638 638 639 ``user_passes_test()`` takes an optional ``login_url`` argument, which lets you 639 specify the URL for your login page (`` /accounts/login/`` by default).640 specify the URL for your login page (``settings.LOGIN_URL`` by default). 640 641 641 642 Example in Python 2.3 syntax:: … … 681 682 682 683 As in the ``login_required`` decorator, ``login_url`` defaults to 683 `` '/accounts/login/'``.684 ``settings.LOGIN_URL``. 684 685 685 686 Limiting access to generic views django/trunk/docs/settings.txt
r5064 r5072 563 563 any code that uses ``LANGUAGES`` at runtime. 564 564 565 LOGIN_URL 566 --------- 567 568 Default: ``'/accounts/login/'`` 569 570 The URL where requests are redirected for login, specially when using the 571 `@login_required`_ decorator. 572 573 LOGOUT_URL 574 ---------- 575 576 Default: ``'/accounts/logout/'`` 577 578 LOGIN_URL counterpart. 579 565 580 MANAGERS 566 581 -------- … … 620 635 See `allowed date format strings`_. See also DATE_FORMAT, DATETIME_FORMAT, 621 636 TIME_FORMAT and YEAR_MONTH_FORMAT. 637 638 LOGIN_REDIRECT_URL 639 ------------------ 640 641 Default: ``'/accounts/profile/'`` 642 643 The URL where requests are redirected after login when the 644 ``contrib.auth.login`` view gets no ``next`` parameter. 645 646 This is used by the `@login_required`_ decorator, for example. 622 647 623 648 PREPEND_WWW … … 1013 1038 ``DJANGO_SETTINGS_MODULE``. Not both, and not neither. 1014 1039 1040 .. _@login_required: ../authentication/#the-login-required-decorator 1041 1015 1042 Error reporting via e-mail 1016 1043 ==========================
