Ticket #12233: patch.diff
File patch.diff, 3.0 KB (added by , 15 years ago) |
---|
-
django/contrib/auth/views.py
18 18 @csrf_protect 19 19 @never_cache 20 20 def login(request, template_name='registration/login.html', 21 redirect_if_logged_in=None, 21 22 redirect_field_name=REDIRECT_FIELD_NAME, 22 23 authentication_form=AuthenticationForm): 23 24 "Displays the login form and handles the login action." 25 if request.user.is_authenticated() and redirect_if_logged_in != None: 26 return HttpResponseRedirect(redirect_if_logged_in) 24 27 redirect_to = request.REQUEST.get(redirect_field_name, '') 25 28 if request.method == "POST": 26 29 form = authentication_form(data=request.POST) -
django/contrib/auth/tests/views.py
184 184 self.login(password='password1') 185 185 186 186 class LoginTest(AuthViewsTestCase): 187 187 def login(self, password='password'): 188 response = self.client.post('/login/', { 189 'username': 'testclient', 190 'password': password 191 } 192 ) 193 self.assertEquals(response.status_code, 302) 194 self.assert_(response['Location'].endswith(settings.LOGIN_REDIRECT_URL)) 195 self.assert_(SESSION_KEY in self.client.session) 196 197 188 198 def test_current_site_in_context_after_login(self): 189 199 response = self.client.get(reverse('django.contrib.auth.views.login')) 190 200 self.assertEquals(response.status_code, 200) … … 193 203 self.assertEquals(response.context['site_name'], site.name) 194 204 self.assert_(isinstance(response.context['form'], AuthenticationForm), 195 205 'Login form is not an AuthenticationForm') 196 206 207 def test_logged_in_user_should_be_redirected(self): 208 "If the user is logged in, we should redirect to the specified page" 209 self.login() 210 response = self.client.get(reverse('django.contrib.auth.views.login', {'redirect_if_logged_in': '/next_page/'})) 211 self.assertEquals(302, response.status_code) 212 self.assertEquals('/next_page/', response['Location']) 213 214 def test_logged_in_user_should_not_be_redirected(self): 215 "If the user is logged in but we don't have any redirect url, we display the login form" 216 self.login() 217 response = self.client.get(reverse('django.contrib.auth.views.login')) 218 self.assertEquals(200, response.status_code) 219 220 def test_guest_should_not_be_redirected(self): 221 "If the user is not logged, we display the login form" 222 response = self.client.get(reverse('django.contrib.auth.views.login', {'redirect_if_logged_in': '/next_page/'})) 223 self.assertEquals(200, response.status_code) 224 197 225 class LogoutTest(AuthViewsTestCase): 198 226 urls = 'django.contrib.auth.tests.urls' 199 227