Changeset 8343
- Timestamp:
- 08/13/08 22:58:00 (11 months ago)
- Files:
-
- django/trunk/django/contrib/auth/__init__.py (modified) (2 diffs)
- django/trunk/docs/authentication.txt (modified) (1 diff)
- django/trunk/docs/sessions.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/auth/__init__.py
r5678 r8343 54 54 user.last_login = datetime.datetime.now() 55 55 user.save() 56 if request.session.get('SESSION_KEY', user.id) != user.id: 57 # To avoid reusing another user's session, create a new, empty session 58 # if the existing session corresponds to a different authenticated user. 59 request.session.flush() 56 60 request.session[SESSION_KEY] = user.id 57 61 request.session[BACKEND_SESSION_KEY] = user.backend … … 61 65 def logout(request): 62 66 """ 63 Remove the authenticated user's ID from the request. 67 Removes the authenticated user's ID from the request and flushes their 68 session data. 64 69 """ 65 try: 66 del request.session[SESSION_KEY] 67 except KeyError: 68 pass 69 try: 70 del request.session[BACKEND_SESSION_KEY] 71 except KeyError: 72 pass 70 request.session.flush() 73 71 if hasattr(request, 'user'): 74 72 from django.contrib.auth.models import AnonymousUser django/trunk/docs/authentication.txt
r8043 r8343 426 426 427 427 Note that ``logout()`` doesn't throw any errors if the user wasn't logged in. 428 429 **New in Django development version:** When you call ``logout()``, the session 430 data for the current request is completely cleaned out. All existing data is 431 removed. This is to prevent another person from using the same web browser to 432 log in and have access to the previous user's session data. If you want to put 433 anything into the session that will be available to the user immediately after 434 logging out, do that *after* calling ``django.contrib.auth.logout()``. 428 435 429 436 Limiting access to logged-in users django/trunk/docs/sessions.txt
r8342 r8343 118 118 session key value that is sent back to the user in the cookie. This is 119 119 used if you want to ensure that the previous session data can't be 120 accessed again from the user's browser (for example, the standard121 `` logout()`` method calls it).120 accessed again from the user's browser (for example, the 121 ``django.contrib.auth.logout()`` method calls it). 122 122 123 123 * ``set_test_cookie()`` … … 230 230 pass 231 231 return HttpResponse("You're logged out.") 232 233 The standard ``django.contrib.auth.logout()`` function actually does a bit 234 more than this to prevent inadvertent data leakage. It calls 235 ``request.session.flush()``. We are using this example as a demonstration of 236 how to work with session objects, not as a full ``logout()`` implementation. 232 237 233 238 Setting test cookies
