From b9186611c1dfa8c38f18775347e4b3aac12ddc6b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 10 Aug 2019 15:12:43 +0200 Subject: [PATCH] auth_fc: differentiate registration login block with a class (#29227) --- src/authentic2/templates/authentic2/login.html | 4 ++-- src/authentic2/utils.py | 7 +++++++ src/authentic2_auth_fc/authenticators.py | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/authentic2/templates/authentic2/login.html b/src/authentic2/templates/authentic2/login.html index fa741634..5e052a36 100644 --- a/src/authentic2/templates/authentic2/login.html +++ b/src/authentic2/templates/authentic2/login.html @@ -25,7 +25,7 @@ {% if blocks|length != 1 %} {% for id, login_block in blocks.items %} {% if not login_block.is_hidden %} - + {{ login_block.name }} {% endif %} @@ -33,7 +33,7 @@ {% endif %} {% for id, login_block in blocks.items %} -
+ {% endfor %} diff --git a/src/authentic2/utils.py b/src/authentic2/utils.py index 851bdf79..1fc00547 100644 --- a/src/authentic2/utils.py +++ b/src/authentic2/utils.py @@ -212,10 +212,16 @@ def get_authenticator_method(authenticator, method, parameters): if not response: return None status_code = 200 + extra_css_class = '' # Some authenticator methods return an HttpResponse, others return a string if isinstance(response, HttpResponse): + # Force a TemplateResponse to be rendered. + if not getattr(response, 'is_rendered', True) and callable(getattr(response, 'render', None)): + response = response.render() content = response.content status_code = response.status_code + if hasattr(response, 'context_data') and response.context_data: + extra_css_class = response.context_data.get('block-extra-css-class', '') return { 'id': authenticator.id, 'name': authenticator.name, @@ -223,6 +229,7 @@ def get_authenticator_method(authenticator, method, parameters): 'response': response, 'status_code': status_code, 'authenticator': authenticator, + 'extra_css_class': extra_css_class, } diff --git a/src/authentic2_auth_fc/authenticators.py b/src/authentic2_auth_fc/authenticators.py index 01097d30..8779b862 100644 --- a/src/authentic2_auth_fc/authenticators.py +++ b/src/authentic2_auth_fc/authenticators.py @@ -17,6 +17,7 @@ from django.utils.translation import gettext_noop from django.template.loader import render_to_string from django.shortcuts import render +from django.template.response import TemplateResponse from authentic2 import app_settings as a2_app_settings, utils as a2_utils @@ -57,6 +58,7 @@ class FcAuthenticator(object): params=params, request=request), 'fc_user_info': fc_user_info, + 'block-extra-css-class': 'fc-registration', }) template = 'authentic2_auth_fc/login_registration.html' else: @@ -64,8 +66,9 @@ class FcAuthenticator(object): keep_params=True, params=params, request=request) + context['block-extra-css-class'] = 'fc-login' template = 'authentic2_auth_fc/login.html' - return render(request, template, context) + return TemplateResponse(request, template, context) def profile(self, request, *args, **kwargs): # We prevent unlinking if the user has no usable password and can't change it -- 2.23.0.rc1