0002-display-service-logo-and-name-on-login-and-registrat.patch
src/authentic2/context_processors.py | ||
---|---|---|
66 | 66 |
variables['USER_SWITCHED'] = constants.SWITCH_USER_SESSION_KEY in request.session |
67 | 67 |
if 'service_pk' in request.session: |
68 | 68 |
try: |
69 |
variables['service'] = Service.objects.get(pk=request.session['service_pk']) |
|
69 |
service = Service.objects.get(pk=request.session['service_pk']) |
|
70 |
variables['service'] = service |
|
71 |
if service.logo: |
|
72 |
variables['service_logo_url'] = service.logo.url |
|
73 |
if service.ou.logo: |
|
74 |
variables['service_ou_logo_url'] = service.ou.logo.url |
|
75 |
variables['service_text_color'] = service.text_color |
|
76 |
variables['service_ou_text_color'] = service.ou.text_color |
|
70 | 77 |
except Service.DoesNotExist: |
71 | 78 |
pass |
72 | 79 |
return variables |
src/authentic2/templates/authentic2/login.html | ||
---|---|---|
15 | 15 |
{% endblock %} |
16 | 16 | |
17 | 17 |
{% block content %} |
18 | ||
19 |
{% include "authentic2/service_info_fragment.html" %} |
|
20 | ||
18 | 21 |
<div id="a2-login-forms"> |
19 | 22 |
{% for id, login_block in blocks.items %} |
20 | 23 |
<span id="css-tab{{ forloop.counter }}"></span> |
src/authentic2/templates/authentic2/service_info_fragment.html | ||
---|---|---|
1 |
{% load i18n %} |
|
2 |
{% if service %} |
|
3 |
{% firstof service_text_color service_ou_text_color as text_color %} |
|
4 |
{% firstof service.home_url service.ou.home_url as home_url %} |
|
5 |
{% if home_url %} |
|
6 |
<div id="service-message"> |
|
7 |
{% block service-logo %} |
|
8 |
{% firstof service_logo_url service_ou_logo_url as logo_url %} |
|
9 |
{% if logo_url %} |
|
10 |
<picture> |
|
11 |
<img src="{{ logo_url }}" alt="{% firstof service.name service.ou.name %}" class="service--logo" /> |
|
12 |
</picture> |
|
13 |
{% endif %} |
|
14 |
{% endblock %} |
|
15 | ||
16 |
<h2> |
|
17 |
<a href="{{ home_url }}"{% if text_color %} style="color: {{ text_color }}"{% endif %} class="service--link"> |
|
18 |
{% block service-name-pre %}{% endblock %} |
|
19 |
{% block service-name %}{% firstof service.name service.ou.name %}{% endblock %} |
|
20 |
{% block service-name-post %}{% endblock %} |
|
21 |
</a> |
|
22 |
</h2> |
|
23 |
</div> |
|
24 |
{% endif %} |
|
25 |
{% endif %} |
src/authentic2/templates/registration/registration_form.html | ||
---|---|---|
9 | 9 | |
10 | 10 |
<h2>{{ view.title }}</h2> |
11 | 11 | |
12 |
{% include "authentic2/service_info_fragment.html" %} |
|
13 | ||
12 | 14 |
{% for id, block in frontends.items %} |
13 | 15 |
<div class="registration_frontend"> |
14 | 16 |
<h2>{{ block.name }}</h2> |
tests/idp_oidc/test_misc.py | ||
---|---|---|
24 | 24 |
from django.contrib.auth import get_user_model |
25 | 25 |
from django.core.exceptions import ValidationError |
26 | 26 |
from django.core.files import File |
27 |
from django.core.files.uploadedfile import SimpleUploadedFile |
|
27 | 28 |
from django.http import QueryDict |
28 | 29 |
from django.test.utils import override_settings |
29 | 30 |
from django.urls import reverse |
... | ... | |
86 | 87 |
'idtoken_duration': '3600', |
87 | 88 |
'post_logout_redirect_uris': 'https://example.com/', |
88 | 89 |
'home_url': 'https://example.com/', |
90 |
'text_color': '#ff00ff', |
|
89 | 91 |
}, |
90 | 92 |
{ |
91 | 93 |
'frontchannel_logout_uri': 'https://example.com/southpark/logout/', |
... | ... | |
93 | 95 |
{ |
94 | 96 |
'frontchannel_logout_uri': 'https://example.com/southpark/logout/', |
95 | 97 |
'frontchannel_timeout': 3000, |
96 |
'text_color': '#ff00ff', |
|
97 | 98 |
}, |
98 | 99 |
{ |
99 | 100 |
'identifier_policy': OIDCClient.POLICY_PAIRWISE_REVERSIBLE, |
... | ... | |
127 | 128 |
assert OIDCClient.objects.count() == 1 |
128 | 129 | |
129 | 130 | |
131 |
def test_login_from_client_with_home_url(oidc_client, app): |
|
132 |
redirect_uri = oidc_client.redirect_uris.split()[0] |
|
133 |
params = { |
|
134 |
'client_id': oidc_client.client_id, |
|
135 |
'scope': 'openid profile email', |
|
136 |
'redirect_uri': redirect_uri, |
|
137 |
'state': 'xxx', |
|
138 |
'nonce': 'yyy', |
|
139 |
'login_hint': 'backoffice john@example.com', |
|
140 |
'response_type': 'code', |
|
141 |
} |
|
142 |
authorize_url = make_url('oidc-authorize', params=params) |
|
143 |
response = app.get(authorize_url).follow() |
|
144 |
assert not response.pyquery.find('#service-message') |
|
145 | ||
146 |
ou = oidc_client.ou |
|
147 |
ou.home_url = 'https://ou.example.net' |
|
148 |
ou.text_color = '#8c00ec' |
|
149 |
ou.logo = SimpleUploadedFile(name='200x200.jpg', content=open('tests/200x200.jpg', 'rb').read()) |
|
150 |
ou.save() |
|
151 |
response = app.get(authorize_url).follow() |
|
152 |
assert response.pyquery.find('#service-message') |
|
153 |
assert response.pyquery.find('a.service--link') |
|
154 |
link = response.pyquery.find('a.service--link')[0] |
|
155 |
assert link.attrib['href'] == 'https://ou.example.net' |
|
156 |
assert link.attrib['style'] == 'color: #8c00ec' |
|
157 |
assert response.pyquery.find('img.service--logo')[0].attrib['src'] == '/media/services/logos/200x200.jpg' |
|
158 | ||
159 |
oidc_client.home_url = 'https://service.example.net' |
|
160 |
oidc_client.text_color = '#ec008c' |
|
161 |
oidc_client.logo = SimpleUploadedFile(name='201x201.jpg', content=open('tests/201x201.jpg', 'rb').read()) |
|
162 |
oidc_client.save() |
|
163 | ||
164 |
response = app.get(authorize_url).follow() |
|
165 |
link = response.pyquery.find('a.service--link')[0] |
|
166 |
assert link.attrib['href'] == 'https://service.example.net' |
|
167 |
assert link.attrib['style'] == 'color: #ec008c' |
|
168 |
assert response.pyquery.find('img.service--logo')[0].attrib['src'] == '/media/services/logos/201x201.jpg' |
|
169 | ||
170 |
# check registration page |
|
171 |
response = response.click('Register!') |
|
172 |
assert link.attrib['href'] == 'https://service.example.net' |
|
173 |
assert link.attrib['style'] == 'color: #ec008c' |
|
174 |
assert response.pyquery.find('img.service--logo')[0].attrib['src'] == '/media/services/logos/201x201.jpg' |
|
175 | ||
176 | ||
130 | 177 |
@pytest.mark.parametrize('oidc_client', OIDC_CLIENT_PARAMS, indirect=True) |
131 | 178 |
@pytest.mark.parametrize('do_not_ask_again', [(True,), (False,)]) |
132 | 179 |
@pytest.mark.parametrize('login_first', [(True,), (False,)]) |
133 |
- |