[1.11.x] Fixed #27815 -- Made LoginView pass the request kwarg to AuthenticationForm.
Backport of 41ba27fefd
from master
This commit is contained in:
parent
8a60e3d3fd
commit
f94e1a5de4
|
@ -107,6 +107,11 @@ class LoginView(SuccessURLAllowedHostsMixin, FormView):
|
||||||
def get_form_class(self):
|
def get_form_class(self):
|
||||||
return self.authentication_form or self.form_class
|
return self.authentication_form or self.form_class
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super(LoginView, self).get_form_kwargs()
|
||||||
|
kwargs['request'] = self.request
|
||||||
|
return kwargs
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
"""Security check complete. Log the user in."""
|
"""Security check complete. Log the user in."""
|
||||||
auth_login(self.request, form.get_user())
|
auth_login(self.request, form.get_user())
|
||||||
|
|
|
@ -598,13 +598,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):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue