Ticket #3185: login_url.patch
File login_url.patch, 10.4 KB (added by , 18 years ago) |
---|
-
django/conf/global_settings.py
312 312 313 313 AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',) 314 314 315 LOGIN_URL = '/accounts/login/' 316 317 LOGOUT_URL = '/accounts/logout/' 318 319 POSTLOGIN_REDIRECT_URL = '/accounts/profile/' 320 315 321 ########### 316 322 # TESTING # 317 323 ########### -
django/contrib/comments/templatetags/comments.py
25 25 self.is_public = is_public 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 30 31 context.push() … … 64 65 if self.rating_options: 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) 69 71 context.pop() -
django/contrib/comments/templates/comments/form.html
3 3 <form {% if photos_optional or photos_required %}enctype="multipart/form-data" {% endif %}action="/comments/post/" method="post"> 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> 9 9 {% endif %} -
django/contrib/auth/views.py
6 6 from django.contrib.sites.models import Site 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'): 12 12 "Displays the login form and handles the login action." … … 17 17 if not errors: 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.POSTLOGIN_REDIRECT_URL 21 22 from django.contrib.auth import login 22 23 login(request, manipulator.get_user()) 23 24 request.session.delete_test_cookie() … … 41 42 # Redirect to this page until the session has been cleared. 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 52 59 def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', -
django/contrib/auth/__init__.py
2 2 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 8 7 def load_backend(path): -
django/contrib/auth/decorators.py
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, 8 8 redirecting to the log-in page if necessary. The test should be a callable 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): 13 16 if test_func(request.user): … … 27 30 """ 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 33 36 enabled, redirecting to the log-in page if necessary. -
docs/settings.txt
562 562 you'll have to remember to wrap the languages in the *real* ``gettext()`` in 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 -------- 567 582 … … 620 635 See `allowed date format strings`_. See also DATE_FORMAT, DATETIME_FORMAT, 621 636 TIME_FORMAT and YEAR_MONTH_FORMAT. 622 637 638 POSTLOGIN_REDIRECT_URL 639 ---------------------- 640 641 Default: ``'/accounts/profile/'`` 642 643 The URL where requests are redirected after login when the ``contrib.auth.login`` 644 view gets no ``next`` parameter. 645 i.e.: When the `@login_required`_ decorator is called. 646 623 647 PREPEND_WWW 624 648 ----------- 625 649 … … 1012 1036 It boils down to this: Use exactly one of either ``configure()`` or 1013 1037 ``DJANGO_SETTINGS_MODULE``. Not both, and not neither. 1014 1038 1039 .. _@login_required: ../authentication/#the-login-required-decorator 1040 1015 1041 Error reporting via e-mail 1016 1042 ========================== 1017 1043 -
docs/authentication.txt
387 387 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'), 400 401 … … 405 406 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.POSTLOGIN_REDIRECT_URL`` 410 which defaults to ``/accounts/profile/``. If login isn't successful, it 411 redisplays the login form. 411 412 412 413 It's your responsibility to provide the login form in a template called 413 414 ``registration/login.html`` by default. This template gets passed three … … 487 488 **Optional arguments:** 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`` 493 494 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 569 570 **Optional arguments:** 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 575 576 --------------------- … … 636 637 is not anonymous. 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:: 642 643 … … 680 681 my_view = permission_required('polls.can_vote', login_url='/loginpage/')(my_view) 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 686 687 --------------------------------