From df346609066e76f22bfd84922efc131ecd7fc817 Mon Sep 17 00:00:00 2001
From: Serghei Mihai <smihai@entrouvert.com>
Date: Mon, 30 May 2022 14:17:13 +0200
Subject: [PATCH] misc: render authenticators names in their own templates
 (#53264)

---
 .../templates/authentic2/login_password_form.html         | 3 +++
 .../authentic2/login_password_registration_form.html      | 6 ++++++
 .../templates/registration/registration_form.html         | 3 ---
 src/authentic2/views.py                                   | 1 +
 src/authentic2_auth_fc/models.py                          | 2 +-
 .../templates/authentic2_auth_fc/login.html               | 7 ++++++-
 .../templates/authentic2_auth_fc/registration.html        | 7 +++++++
 src/authentic2_auth_fc/views.py                           | 8 +++++++-
 8 files changed, 31 insertions(+), 6 deletions(-)
 create mode 100644 src/authentic2_auth_fc/templates/authentic2_auth_fc/registration.html

diff --git a/src/authentic2/templates/authentic2/login_password_form.html b/src/authentic2/templates/authentic2/login_password_form.html
index ae1fec5fc..1e83d44cf 100644
--- a/src/authentic2/templates/authentic2/login_password_form.html
+++ b/src/authentic2/templates/authentic2/login_password_form.html
@@ -1,5 +1,8 @@
 {% load i18n static gadjo %}
 
+{% block login-block-title %}
+{% endblock %}
+
 {% block login %}
 
 {% block form %}
diff --git a/src/authentic2/templates/authentic2/login_password_registration_form.html b/src/authentic2/templates/authentic2/login_password_registration_form.html
index 003b87d11..d2e86712f 100644
--- a/src/authentic2/templates/authentic2/login_password_registration_form.html
+++ b/src/authentic2/templates/authentic2/login_password_registration_form.html
@@ -1,6 +1,11 @@
 {% load i18n gadjo %}
 
+{% 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 }}
@@ -8,4 +13,5 @@
   <button class="submit-button">{% trans 'Submit' %}</button>
   </div>
 </form>
+</p>
 {% endblock %}
diff --git a/src/authentic2/templates/registration/registration_form.html b/src/authentic2/templates/registration/registration_form.html
index 29b0151a6..31e61ea8c 100644
--- a/src/authentic2/templates/registration/registration_form.html
+++ b/src/authentic2/templates/registration/registration_form.html
@@ -13,10 +13,7 @@
 
 {% for id, block in frontends.items %}
   <div class="registration_frontend">
-    <h2>{{ block.name }}</h2>
-    <p>
       {{ block.content|safe }}
-    </p>
   </div>
 {% endfor %}
 
diff --git a/src/authentic2/views.py b/src/authentic2/views.py
index cb8d410d6..9c8967209 100644
--- a/src/authentic2/views.py
+++ b/src/authentic2/views.py
@@ -715,6 +715,7 @@ def login_password_login(request, authenticator, *args, **kwargs):
     is_secure = request.is_secure
     context['submit_name'] = 'login-password-submit'
     context['authenticator'] = authenticator
+    context['block_title'] = authenticator._meta.verbose_name
     if is_post:
         csrf_token_check(request, form)
         if form.is_valid():
diff --git a/src/authentic2_auth_fc/models.py b/src/authentic2_auth_fc/models.py
index 304cc0bfb..3c09dc0f7 100644
--- a/src/authentic2_auth_fc/models.py
+++ b/src/authentic2_auth_fc/models.py
@@ -130,7 +130,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):
diff --git a/src/authentic2_auth_fc/templates/authentic2_auth_fc/login.html b/src/authentic2_auth_fc/templates/authentic2_auth_fc/login.html
index e7486bd4f..c15d7334d 100644
--- a/src/authentic2_auth_fc/templates/authentic2_auth_fc/login.html
+++ b/src/authentic2_auth_fc/templates/authentic2_auth_fc/login.html
@@ -1,7 +1,12 @@
 {% load static %}
 {% load i18n %}
 
-{% block login %}
+{% block title %}
+{% block login-block-title %}
+{% endblock %}
+{% endblock %}
+
+{% block content %}
 <div id="fc-button-wrapper">
   <div id="fc-button">
     <a href="{{ login_url }}"
diff --git a/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration.html b/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration.html
new file mode 100644
index 000000000..9afa75fc7
--- /dev/null
+++ b/src/authentic2_auth_fc/templates/authentic2_auth_fc/registration.html
@@ -0,0 +1,7 @@
+{% extends "authentic2_auth_fc/login.html" %}
+
+{% block title %}
+{% block registration-block-title %}
+<h2>{{ block_title }}</h2>
+{% endblock %}
+{% endblock %}
diff --git a/src/authentic2_auth_fc/views.py b/src/authentic2_auth_fc/views.py
index 60f98c9c2..0b21f2187 100644
--- a/src/authentic2_auth_fc/views.py
+++ b/src/authentic2_auth_fc/views.py
@@ -76,10 +76,16 @@ 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'
+    context['block_title'] = models.FcAuthenticator._meta.verbose_name
+    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
-- 
2.37.2

