From 98879301de2c5129686cc1c0b29e8bfa73d91bcf Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 26 Jul 2022 17:30:43 +0200 Subject: [PATCH 4/4] password: use login form customization fields (#51363) --- src/authentic2/apps/authenticators/forms.py | 2 +- .../templates/authentic2/login_password_form.html | 4 ++++ src/authentic2/views.py | 1 + tests/test_login.py | 7 +++++++ tests/test_manager_authenticators.py | 1 - 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/authentic2/apps/authenticators/forms.py b/src/authentic2/apps/authenticators/forms.py index 75351c6e..c57af967 100644 --- a/src/authentic2/apps/authenticators/forms.py +++ b/src/authentic2/apps/authenticators/forms.py @@ -70,4 +70,4 @@ class AuthenticatorAddForm(SlugMixin, forms.ModelForm): class LoginPasswordAuthenticatorEditForm(AuthenticatorFormMixin, forms.ModelForm): class Meta: model = LoginPasswordAuthenticator - exclude = ('name', 'slug', 'ou') + exclude = ('name', 'slug', 'ou', 'button_label') diff --git a/src/authentic2/templates/authentic2/login_password_form.html b/src/authentic2/templates/authentic2/login_password_form.html index 55ba7270..ae1fec5f 100644 --- a/src/authentic2/templates/authentic2/login_password_form.html +++ b/src/authentic2/templates/authentic2/login_password_form.html @@ -3,6 +3,10 @@ {% block login %} {% block form %} +{% if authenticator.button_description %} +

{{ authenticator.button_description }}

+{% endif %} +
{% csrf_token %} diff --git a/src/authentic2/views.py b/src/authentic2/views.py index e8492170..e1ee81be 100644 --- a/src/authentic2/views.py +++ b/src/authentic2/views.py @@ -763,6 +763,7 @@ def login_password_login(request, authenticator, *args, **kwargs): form.fields['username'].label = app_settings.A2_USERNAME_LABEL is_secure = request.is_secure context['submit_name'] = 'login-password-submit' + context['authenticator'] = authenticator if is_post: csrf_token_check(request, form) if form.is_valid(): diff --git a/tests/test_login.py b/tests/test_login.py index 3c5ede64..0208b263 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -364,6 +364,13 @@ def test_token_login(app, simple_user): assert_event('user.login', user=simple_user, session=app.session, how='token') +def test_button_description(app, db): + LoginPasswordAuthenticator.objects.update(button_description='This is a test.') + + response = app.get('/login/') + assert 'This is a test.' in response.text + + def test_password_authenticator_data_migration(migration, settings): app = 'authenticators' migrate_from = [(app, '0002_loginpasswordauthenticator')] diff --git a/tests/test_manager_authenticators.py b/tests/test_manager_authenticators.py index da272295..5f8945ac 100644 --- a/tests/test_manager_authenticators.py +++ b/tests/test_manager_authenticators.py @@ -57,7 +57,6 @@ def test_authenticators_password(app, superuser): 'csrfmiddlewaretoken', 'show_condition', 'button_description', - 'button_label', 'remember_me', 'include_ou_selector', None, -- 2.30.2