Ticket #3185: 3185_3.diff

File 3185_3.diff, 6.6 KB (added by Vasily Sulatskov <redvasily@…>, 17 years ago)

Added LOGOUT_URL variable to auth/init.py. Modified comments app to use it.

  • django/contrib/comments/templatetags/comments.py

     
    55from django.template import loader
    66from django.core.exceptions import ObjectDoesNotExist
    77from django.contrib.contenttypes.models import ContentType
     8from django.contrib.auth import LOGOUT_URL
    89import re
    910
    1011register = template.Library()
     
    6465            if self.rating_options:
    6566                context['rating_range'], context['rating_choices'] = Comment.objects.get_rating_options(self.rating_options)
    6667            context['hash'] = Comment.objects.get_security_hash(context['options'], context['photo_options'], context['rating_options'], context['target'])
     68            context['logout_url'] = LOGOUT_URL
    6769            default_form = loader.get_template(COMMENT_FORM)
    6870        output = default_form.render(context)
    6971        context.pop()
  • django/contrib/comments/templates/comments/form.html

     
    33<form {% if photos_optional or photos_required %}enctype="multipart/form-data" {% endif %}action="/comments/post/" method="post">
    44
    55{% 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>
    77{% else %}
    88<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>
    99{% endif %}
  • django/contrib/auth/views.py

     
    66from django.contrib.sites.models import Site
    77from django.http import HttpResponseRedirect
    88from django.contrib.auth.decorators import login_required
    9 from django.contrib.auth import LOGIN_URL, REDIRECT_FIELD_NAME
     9from django.contrib.auth import LOGIN_URL, ACCOUNT_URL, REDIRECT_FIELD_NAME
    1010
    1111def login(request, template_name='registration/login.html'):
    1212    "Displays the login form and handles the login action."
     
    1717        if not errors:
    1818            # Light security check -- make sure redirect_to isn't garbage.
    1919            if not redirect_to or '://' in redirect_to or ' ' in redirect_to:
    20                 redirect_to = '/accounts/profile/'
     20                redirect_to = ACCOUNT_URL
    2121            from django.contrib.auth import login
    2222            login(request, manipulator.get_user())
    2323            request.session.delete_test_cookie()
  • django/contrib/auth/__init__.py

     
     1from django.conf import settings
    12from django.core.exceptions import ImproperlyConfigured
    23
    34SESSION_KEY = '_auth_user_id'
     
    23BACKEND_SESSION_KEY = '_auth_user_backend'
    3 LOGIN_URL = '/accounts/login/'
     4LOGIN_URL = getattr(settings, 'LOGIN_URL', '/accounts/login/')
     5LOGOUT_URL = getattr(settings, 'LOGOUT_URL', '/accounts/logout/')
     6ACCOUNT_URL = getattr(settings, 'ACCOUNT_URL', '/accounts/profile/')
    47REDIRECT_FIELD_NAME = 'next'
  • docs/settings.txt

     
    166166        'news.Story': lambda o: "/stories/%s/%s/" % (o.pub_year, o.slug),
    167167    }
    168168
     169ACCOUNT_URL
     170-------------
     171
     172Default: ``'/accounts/profile/'``
     173
     174The URL where requests are redirected after login when the ``"contrib.auth.login"`` view
     175gets no ``next`` parameter.
     176i.e.: When the `@login_required`_ decorator is called
     177
    169178ADMIN_FOR
    170179---------
    171180
     
    533542you'll have to remember to wrap the languages in the *real* ``gettext()`` in
    534543any code that uses ``LANGUAGES`` at runtime.
    535544
     545LOGIN_URL
     546-------------
     547
     548Default: ``'/accounts/login/'``
     549
     550The URL where requests are redirected for login, specially when using the
     551`@login_required`_ decorator.
     552
     553LOGOUT_URL
     554-------------
     555
     556Default: ``'/accounts/logout/'``
     557
     558LOGIN_URL counterpart.
     559
    536560MANAGERS
    537561--------
    538562
     
    972996
    973997It boils down to this: Use exactly one of either ``configure()`` or
    974998``DJANGO_SETTINGS_MODULE``. Not both, and not neither.
     999
     1000.. _@login_required: ../authentication/#the-login-required-decorator
  • docs/authentication.txt

     
    377377
    378378``login_required`` does the following:
    379379
    380     * If the user isn't logged in, redirect to ``/accounts/login/``, passing
    381       the current absolute URL in the query string as ``next``. For example:
     380    * If the user isn't logged in, redirect to ``"settings.LOGIN_URL"``
     381      (``"/accounts/login/"`` by default), passing the current absolute URL
     382      in the query string as ``next``. For example:
    382383      ``/accounts/login/?next=/polls/3/``.
    383384    * If the user is logged in, execute the view normally. The view code is
    384385      free to assume the user is logged in.
    385386
    386 Note that you'll need to map the appropriate Django view to ``/accounts/login/``.
    387 To do this, add the following line to your URLconf::
     387Note that you'll need to map the appropriate Django view to ``"settings.LOGIN_URL"``.
     388For example, using the defaults, add the following line to your URLconf::
    388389
    389390    (r'^accounts/login/$', 'django.contrib.auth.views.login'),
    390391
     
    395396
    396397    * If called via ``POST``, it tries to log the user in. If login is
    397398      successful, the view redirects to the URL specified in ``next``. If
    398       ``next`` isn't provided, it redirects to ``/accounts/profile/`` (which is
    399       currently hard-coded). If login isn't successful, it redisplays the login
     399      ``next`` isn't provided, it redirects to ``"settings.ACCOUNT_URL"`` which
     400      defaults to ``/accounts/profile/``. If login isn't successful, it redisplays the login
    400401      form.
    401402
    402403It's your responsibility to provide the login form in a template called
Back to Top