misc: render authenticators names in their own templates (#53264)

This commit is contained in:
Serghei Mihai 2022-11-15 18:58:38 +01:00 committed by Gitea
parent 1aeb81e3a1
commit cd1a6e5cf4
15 changed files with 108 additions and 41 deletions

View File

@ -1,13 +1,15 @@
{% load i18n static gadjo %}
{% block login-block-title %}
{% endblock %}
{% block login %}
<div>
{% block form %}
{% if authenticator.button_description %}
<p>{{ authenticator.button_description }}</p>
{% endif %}
{% block form %}
{% if authenticator.button_description %}
<p>{{ authenticator.button_description }}</p>
{% endif %}
<div>
<form method="post" id="login-password-form" class="pk-mark-optional-fields">
{% csrf_token %}
{{ form|with_template }}
@ -21,22 +23,21 @@
{% endblock %}
</form>
{{ form.media }}
</div>
{% endblock %}
{% block actions %}
{% if can_reset_password or registration_authorized %}
<div class="login-actions">
<ul>
{% if can_reset_password %}
<li><p>→ {% trans "Forgot password?" %} <a href="{% url 'password_reset' %}{% if request.GET.next %}?next={{ request.GET.next|urlencode }}{% endif %}">{% trans "Reset it!" %}</a></p></li>
{% endif %}
{% if registration_authorized and not hide_login_registration_link %}
<li><p>→ {% trans "Not a member?" %} <a href="{{ registration_url }}">{% trans "Register!" %}</a></p></li>
{% endif %}
</ul>
</div>
{% endif %}
{% endblock %}
{% endblock %}
{% block actions %}
{% if can_reset_password or registration_authorized %}
<div class="login-actions">
<ul>
{% if can_reset_password %}
<li><p>→ {% trans "Forgot password?" %} <a href="{% url 'password_reset' %}{% if request.GET.next %}?next={{ request.GET.next|urlencode }}{% endif %}">{% trans "Reset it!" %}</a></p></li>
{% endif %}
{% if registration_authorized and not hide_login_registration_link %}
<li><p>→ {% trans "Not a member?" %} <a href="{{ registration_url }}">{% trans "Register!" %}</a></p></li>
{% endif %}
</ul>
</div>
{% endif %}
{% endblock %}
</div>
{% endblock %}

View File

@ -1,11 +1,17 @@
{% load i18n gadjo %}
{% block registration %}
<form enctype="multipart/form-data" method="post" class="pk-mark-optional-fields">
{% csrf_token %}
{{ form|with_template }}
<div class="buttons">
<button class="submit-button">{% trans 'Submit' %}</button>
</div>
</form>
{% block registration-block-title %}
<h2>{% trans "Registration" %}</h2>
{% endblock %}
{% block registration %}
<p>
<form enctype="multipart/form-data" method="post" class="pk-mark-optional-fields">
{% csrf_token %}
{{ form|with_template }}
<div class="buttons">
<button class="submit-button">{% trans 'Submit' %}</button>
</div>
</form>
</p>
{% endblock %}

View File

@ -7,16 +7,11 @@
{% block content %}
<h2>{{ view.title }}</h2>
{% include "authentic2/service_info_fragment.html" %}
{% for id, block in frontends.items %}
<div class="registration_frontend">
<h2>{{ block.name }}</h2>
<p>
{{ block.content|safe }}
</p>
{{ block.content|safe }}
</div>
{% endfor %}

View File

@ -136,7 +136,7 @@ class FcAuthenticator(BaseAuthenticator):
return views.profile(request, *args, **kwargs)
def registration(self, request, *args, **kwargs):
return self.login(request, *args, **kwargs)
return views.registration(request, *args, **kwargs)
class FcAccount(models.Model):

View File

@ -1,7 +1,12 @@
{% load static %}
{% load i18n %}
{% block login %}
{% block title %}
{% block login-block-title %}
{% endblock %}
{% endblock %}
{% block content %}
{% include "authentic2_auth_fc/explanation.html" %}
<div id="fc-button-wrapper">
<div id="fc-button">

View File

@ -0,0 +1,7 @@
{% extends "authentic2_auth_fc/login.html" %}
{% block title %}
{% block registration-block-title %}
<h2>FranceConnect</h2>
{% endblock %}
{% endblock %}

View File

@ -77,10 +77,15 @@ def login(request, *args, **kwargs):
)
context['login_url'] = utils_misc.make_url('fc-login-or-link', keep_params=True, request=request)
context['block-extra-css-class'] = 'fc-login'
template = 'authentic2_auth_fc/login.html'
template = kwargs.get('template', 'authentic2_auth_fc/login.html')
return TemplateResponse(request, template, context)
def registration(request, *args, **kwargs):
kwargs['template'] = 'authentic2_auth_fc/registration.html'
return login(request, *args, **kwargs)
def profile(request, *args, **kwargs):
# We prevent unlinking if the user has no usable password and can't change it
# because we assume that the password is the unique other mean of authentication

View File

@ -1,5 +1,8 @@
{% load i18n %}
{% block login-block-title %}
{% endblock %}
{% block before-login %}
{% if authenticator.button_description %}
<p>{{ authenticator.button_description }}</p>

View File

@ -35,6 +35,7 @@ from authentic2.manager.utils import get_ou_count
from authentic2.models import Attribute, Service
from authentic2.utils import hooks as a2_hooks
from authentic2.utils.evaluate import BaseExpressionValidator
from authentic2_auth_fc.models import FcAuthenticator
from authentic2_auth_oidc.utils import get_provider_by_issuer
from authentic2_idp_oidc.models import OIDCClient
@ -556,3 +557,14 @@ def scoped_db(django_db_setup, django_db_blocker):
transaction.set_rollback(True)
return scoped_db
@pytest.fixture
def fc(db):
FcAuthenticator.objects.create(
enabled=True,
client_id='xxx',
client_secret='yyy',
platform='test',
scopes=['profile', 'email'],
)

View File

@ -73,7 +73,7 @@ A2_VALIDATE_EMAIL_DOMAIN = False
A2_HOOKS_PROPAGATE_EXCEPTIONS = True
TEMPLATES[0]['DIRS'].append('tests/templates') # pylint: disable=undefined-variable
TEMPLATES[0]['DIRS'].insert(0, 'tests/templates') # pylint: disable=undefined-variable
TEMPLATES[0]['OPTIONS']['debug'] = True # pylint: disable=undefined-variable
SITE_BASE_URL = 'https://testserver'

View File

@ -0,0 +1,3 @@
{% extends "authentic2/login_password_form.html" %}
{% block login-block-title %}<h2>Log in with Password</h2>{% endblock %}

View File

@ -0,0 +1,4 @@
{% extends "authentic2/login_password_registration_form.html" %}
{% block registration-block-title %}
<h2>Register with Password</h2>
{% endblock %}

View File

@ -0,0 +1,5 @@
{% extends "authentic2_auth_fc/login.html" %}
{% block login-block-title %}
<h2>Log in with FC</h2>
{% endblock %}

View File

@ -0,0 +1,5 @@
{% extends "authentic2_auth_fc/registration.html" %}
{% block registration-block-title %}
<h2>Register with FC</h2>
{% endblock %}

View File

@ -16,6 +16,7 @@
import pytest
from authentic2.utils import misc as utils_misc
from authentic2.utils.template import Template, TemplateError
pytestmark = pytest.mark.django_db
@ -108,3 +109,18 @@ def test_render_template_missing_variable():
with pytest.raises(TemplateError) as raised:
template.render(context=context)
assert 'missing template variable' in raised
def test_registration_with_custom_titles(app, fc):
url = utils_misc.make_url('registration_register')
response = app.get(url)
assert '<h2>Registration</h2>' not in response.text
assert '<h2>Register with Password</h2>' in response.text
assert '<h2>Register with FC</h2>' in response.text
def test_login_with_custom_titles(app, fc):
url = utils_misc.make_url('auth_login')
response = app.get(url)
assert '<h2>Log in with Password</h2>' in response.text
assert '<h2>Log in with FC</h2>' in response.text