From 487517291a1e852aa5bb7118918b10d51e63cd61 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 1 Jun 2020 14:40:56 +0200 Subject: [PATCH] authenticators: delete test cookie when authentication is successful (#43473) --- src/authentic2/authenticators.py | 4 +++- src/authentic2/utils/views.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/authentic2/authenticators.py b/src/authentic2/authenticators.py index 208729e0..7b7a721d 100644 --- a/src/authentic2/authenticators.py +++ b/src/authentic2/authenticators.py @@ -119,7 +119,7 @@ class LoginPasswordAuthenticator(BaseAuthenticator): is_secure = request.is_secure context['submit_name'] = self.submit_name if is_post: - test_cookie_check(request) + test_cookie_check(request, delete=False) utils.csrf_token_check(request, form) if form.is_valid(): if is_secure: @@ -133,6 +133,8 @@ class LoginPasswordAuthenticator(BaseAuthenticator): service_slug=service_slug) if 'ou' in form.fields: utils.prepend_remember_cookie(request, response, 'preferred-ous', form.cleaned_data['ou'].pk) + + request.session.delete_test_cookie() return response context['form'] = form return render(request, 'authentic2/login_password_form.html', context) diff --git a/src/authentic2/utils/views.py b/src/authentic2/utils/views.py index 6cbed813..3a31ef48 100644 --- a/src/authentic2/utils/views.py +++ b/src/authentic2/utils/views.py @@ -18,7 +18,7 @@ from django.contrib import messages from django.utils.translation import gettext as _ -def test_cookie_check(request): +def test_cookie_check(request, delete=True): '''Verify the test cookie is set, if not log a message for the user explaining the problem. It should only be used in views in which we are sure of coming from the login page. @@ -30,4 +30,5 @@ def test_cookie_check(request): request, _('Cookies are disabled in your browser, please activate them or you will not be able to log in.')) else: - request.session.delete_test_cookie() + if delete: + request.session.delete_test_cookie() -- 2.26.2