Ticket #10460: fixed-auth-logout-with-redirect.diff
File fixed-auth-logout-with-redirect.diff, 3.6 KB (added by , 16 years ago) |
---|
-
django/contrib/auth/views.py
42 42 }, context_instance=RequestContext(request)) 43 43 login = never_cache(login) 44 44 45 def logout(request, next_page=None, template_name='registration/logged_out.html' ):45 def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME): 46 46 "Logs out the user and displays 'You are logged out' message." 47 47 from django.contrib.auth import logout 48 48 logout(request) 49 49 if next_page is None: 50 return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request)) 50 redirect_to = request.REQUEST.get(redirect_field_name, '') 51 if redirect_to: 52 return HttpResponseRedirect(redirect_to) 53 else: 54 return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request)) 51 55 else: 52 56 # Redirect to this page until the session has been cleared. 53 57 return HttpResponseRedirect(next_page or request.path) -
django/contrib/auth/tests/views.py
3 3 import re 4 4 5 5 from django.conf import settings 6 from django.contrib.auth import SESSION_KEY 6 7 from django.contrib.auth.models import User 7 8 from django.test import TestCase 8 9 from django.core import mail 9 10 11 class LogoutTest(TestCase): 12 fixtures = ['authtestdata.json'] 13 urls = 'django.contrib.auth.urls' 14 15 def login(self, password='password'): 16 response = self.client.post('/login/', { 17 'username': 'testclient', 18 'password': password 19 } 20 ) 21 self.assertEquals(response.status_code, 302) 22 self.assert_(response['Location'].endswith(settings.LOGIN_REDIRECT_URL)) 23 self.assert_(SESSION_KEY in self.client.session) 24 25 def confirm_logged_out(self): 26 self.assert_(SESSION_KEY not in self.client.session) 27 28 def test_logout_default(self): 29 "Logout without next_page option renders the default template" 30 self.login() 31 response = self.client.get('/logout/') 32 self.assertEquals(200, response.status_code) 33 self.assert_('Logged out' in response.content) 34 self.confirm_logged_out() 35 36 def test_logout_with_redirect_argument(self): 37 "Logout with next_page option redirects to specified resource" 38 self.login() 39 response = self.client.get('/logout/?next=/login/') 40 self.assertEqual(response.status_code, 302) 41 self.assert_(response['Location'].endswith('/login/')) 42 self.confirm_logged_out() 43 44 10 45 class PasswordResetTest(TestCase): 11 46 fixtures = ['authtestdata.json'] 12 47 urls = 'django.contrib.auth.urls' -
django/contrib/auth/tests/__init__.py
1 1 from django.contrib.auth.tests.basic import BASIC_TESTS 2 2 from django.contrib.auth.tests.views \ 3 import PasswordResetTest, ChangePasswordTest 3 import PasswordResetTest, ChangePasswordTest, LogoutTest 4 4 from django.contrib.auth.tests.forms import FORM_TESTS 5 5 from django.contrib.auth.tests.remote_user \ 6 6 import RemoteUserTest, RemoteUserNoCreateTest, RemoteUserCustomTest