0003-auth_saml-use-login-form-customization-fields-51363.patch
src/authentic2_auth_saml/migrations/0003_auto_20220726_1713.py | ||
---|---|---|
1 |
# Generated by Django 2.2.26 on 2022-07-26 15:13 |
|
2 | ||
3 |
from django.conf import settings |
|
4 |
from django.db import migrations |
|
5 |
from django.utils import translation |
|
6 |
from django.utils.translation import ugettext as _ |
|
7 | ||
8 | ||
9 |
def set_default_button_label(apps, schema_editor): |
|
10 |
SAMLAuthenticator = apps.get_model('authentic2_auth_saml', 'SAMLAuthenticator') |
|
11 |
with translation.override(settings.LANGUAGE_CODE): |
|
12 |
SAMLAuthenticator.objects.update(button_label=_('Login')) |
|
13 | ||
14 | ||
15 |
class Migration(migrations.Migration): |
|
16 | ||
17 |
dependencies = [ |
|
18 |
('authentic2_auth_saml', '0002_auto_20220608_1559'), |
|
19 |
('authenticators', '0004_auto_20220726_1708'), |
|
20 |
] |
|
21 | ||
22 |
operations = [ |
|
23 |
migrations.RunPython(set_default_button_label, reverse_code=migrations.RunPython.noop), |
|
24 |
] |
src/authentic2_auth_saml/templates/authentic2_auth_saml/login.html | ||
---|---|---|
1 | 1 |
{% load i18n %} |
2 | 2 | |
3 | 3 |
{% block before-login %} |
4 |
{% if authenticator.button_description %} |
|
5 |
<p>{{ authenticator.button_description }}</p> |
|
6 |
{% endif %} |
|
4 | 7 |
{% endblock %} |
5 | 8 | |
6 | 9 |
{% block login %} |
7 | 10 |
<form method="post"> |
8 | 11 |
<div class="buttons"> |
9 |
<button class="submit-button" name="{{ submit_name }}">{% trans "Login" %}</button>
|
|
12 |
<button class="submit-button" name="{{ submit_name }}">{{ authenticator.button_label }}</button>
|
|
10 | 13 |
{% if cancel %} |
11 | 14 |
<button class="cancel-button" name="cancel" formnovalidate>{% trans 'Cancel' %}</button> |
12 | 15 |
{% endif %} |
src/authentic2_auth_saml/views.py | ||
---|---|---|
9 | 9 |
context = kwargs.pop('context', {}).copy() |
10 | 10 |
submit_name = 'login-saml-%s' % authenticator.slug |
11 | 11 |
context['submit_name'] = submit_name |
12 |
context['authenticator'] = authenticator |
|
12 | 13 |
if request.method == 'POST' and submit_name in request.POST: |
13 | 14 |
from .adapters import AuthenticAdapter |
14 | 15 |
tests/test_auth_saml.py | ||
---|---|---|
45 | 45 | |
46 | 46 | |
47 | 47 |
def test_providers_on_login_page(db, app, settings): |
48 |
SAMLAuthenticator.objects.create(enabled=True, metadata='meta1.xml', slug='idp1') |
|
48 |
SAMLAuthenticator.objects.create( |
|
49 |
enabled=True, |
|
50 |
metadata='meta1.xml', |
|
51 |
slug='idp1', |
|
52 |
button_label='Test label', |
|
53 |
button_description='This is a test.', |
|
54 |
) |
|
49 | 55 | |
50 | 56 |
response = app.get('/login/') |
51 | 57 |
assert response.pyquery('button[name="login-saml-idp1"]') |
... | ... | |
57 | 63 |
# two frontends should be present on login page |
58 | 64 |
assert response.pyquery('button[name="login-saml-idp1"]') |
59 | 65 |
assert response.pyquery('button[name="login-saml-idp2"]') |
66 |
assert 'Test label' in response.text |
|
67 |
assert 'This is a test.' in response.text |
|
60 | 68 | |
61 | 69 | |
62 | 70 |
@pytest.fixture |
63 |
- |