Fixed #27815 -- Made LoginView pass the request kwarg to AuthenticationForm.

This commit is contained in:
Zoltan Gyarmati 2017-02-07 10:17:36 +01:00 committed by Tim Graham
parent 10c47f7b47
commit 41ba27fefd
2 changed files with 11 additions and 5 deletions

View File

@ -100,6 +100,11 @@ class LoginView(SuccessURLAllowedHostsMixin, FormView):
context.update(self.extra_context) context.update(self.extra_context)
return context return context
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['request'] = self.request
return kwargs
def login(request, *args, **kwargs): def login(request, *args, **kwargs):
warnings.warn( warnings.warn(

View File

@ -594,13 +594,14 @@ class LoginTest(AuthViewsTestCase):
self.assertEqual(response.url, settings.LOGIN_REDIRECT_URL) self.assertEqual(response.url, settings.LOGIN_REDIRECT_URL)
def test_login_form_contains_request(self): def test_login_form_contains_request(self):
# 15198 # The custom authentication form for this login requires a request to
self.client.post('/custom_requestauth_login/', { # initialize it.
response = self.client.post('/custom_request_auth_login/', {
'username': 'testclient', 'username': 'testclient',
'password': 'password', 'password': 'password',
}, follow=True) })
# the custom authentication form used by this login asserts # The login was successful.
# that a request is passed to the form successfully. self.assertRedirects(response, settings.LOGIN_REDIRECT_URL, fetch_redirect_response=False)
def test_login_csrf_rotate(self): def test_login_csrf_rotate(self):
""" """