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 |
variables['service_colour'] = service.colour |
|
72 |
if service.logo: |
|
73 |
variables['service_logo_url'] = service.logo.url |
|
74 |
if service.ou: |
|
75 |
variables['service_ou_colour'] = service.ou.colour |
|
76 |
if service.ou.logo: |
|
77 |
variables['service_ou_logo_url'] = service.ou.logo.url |
|
78 | ||
70 | 79 |
except Service.DoesNotExist: |
71 | 80 |
pass |
72 | 81 |
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_colour service_ou_colour as colour %} |
|
4 |
{% firstof service.home_url service.ou.home_url as home_url %} |
|
5 |
{% firstof service.name service.ou.name as name %} |
|
6 | ||
7 |
{% if home_url %} |
|
8 |
{% block service-colour %} |
|
9 |
{% if colour %} |
|
10 |
<style> |
|
11 |
a.service--link { |
|
12 |
color: {{ colour }}; |
|
13 |
} |
|
14 |
</style> |
|
15 |
{% endif %} |
|
16 |
{% endblock %} |
|
17 | ||
18 |
<div id="service-message"> |
|
19 |
{% firstof service_logo_url service_ou_logo_url as logo_url %} |
|
20 |
{% block service-logo %} |
|
21 |
{% if logo_url %} |
|
22 |
<picture> |
|
23 |
<a href="{{ home_url }}"><img src="{{ logo_url }}" alt="{{ name }}" class="service--logo" /></a> |
|
24 |
</picture> |
|
25 |
{% endif %} |
|
26 |
{% endblock %} |
|
27 | ||
28 |
<div> |
|
29 |
<a href="{{ home_url }}" class="service--link"> |
|
30 |
{% block service-name-pre %}{% endblock %} |
|
31 |
{% block service-name %}{{ name }}{% endblock %} |
|
32 |
{% block service-name-post %}{% endblock %} |
|
33 |
</a> |
|
34 |
</div> |
|
35 |
</div> |
|
36 |
{% endif %} |
|
37 | ||
38 |
{% 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 |
... | ... | |
129 | 130 |
assert OIDCClient.objects.count() == 1 |
130 | 131 | |
131 | 132 | |
133 |
def test_login_from_client_with_home_url(oidc_client, app): |
|
134 |
redirect_uri = oidc_client.redirect_uris.split()[0] |
|
135 |
params = { |
|
136 |
'client_id': oidc_client.client_id, |
|
137 |
'scope': 'openid profile email', |
|
138 |
'redirect_uri': redirect_uri, |
|
139 |
'state': 'xxx', |
|
140 |
'nonce': 'yyy', |
|
141 |
'login_hint': 'backoffice john@example.com', |
|
142 |
'response_type': 'code', |
|
143 |
} |
|
144 |
authorize_url = make_url('oidc-authorize', params=params) |
|
145 |
response = app.get(authorize_url).follow() |
|
146 |
assert not response.pyquery.find('#service-message') |
|
147 | ||
148 |
ou = oidc_client.ou |
|
149 |
ou.home_url = 'https://ou.example.net' |
|
150 |
ou.colour = '#8c00ec' |
|
151 |
with open('tests/200x200.jpg', 'rb') as fd: |
|
152 |
ou.logo = SimpleUploadedFile(name='200x200.jpg', content=fd.read()) |
|
153 |
ou.save() |
|
154 |
response = app.get(authorize_url).follow() |
|
155 |
assert response.pyquery.find('#service-message') |
|
156 |
assert response.pyquery.find('a.service--link') |
|
157 |
link = response.pyquery.find('a.service--link')[0] |
|
158 |
assert link.attrib['href'] == 'https://ou.example.net' |
|
159 |
print(response.text) |
|
160 |
assert 'color: #8c00ec' in response.text |
|
161 |
assert response.pyquery.find('img.service--logo')[0].attrib['src'] == '/media/services/logos/200x200.jpg' |
|
162 | ||
163 |
oidc_client.home_url = 'https://service.example.net' |
|
164 |
oidc_client.colour = '#ec008c' |
|
165 |
with open('tests/201x201.jpg', 'rb') as fd: |
|
166 |
oidc_client.logo = SimpleUploadedFile(name='201x201.jpg', content=fd.read()) |
|
167 |
oidc_client.save() |
|
168 | ||
169 |
response = app.get(authorize_url).follow() |
|
170 |
link = response.pyquery.find('a.service--link')[0] |
|
171 |
assert link.attrib['href'] == 'https://service.example.net' |
|
172 |
assert 'color: #ec008c' in response.text |
|
173 |
assert response.pyquery.find('img.service--logo')[0].attrib['src'] == '/media/services/logos/201x201.jpg' |
|
174 | ||
175 |
# check registration page |
|
176 |
response = response.click('Register!') |
|
177 |
assert link.attrib['href'] == 'https://service.example.net' |
|
178 |
assert response.pyquery.find('img.service--logo')[0].attrib['src'] == '/media/services/logos/201x201.jpg' |
|
179 | ||
180 | ||
132 | 181 |
@pytest.mark.parametrize('oidc_client', OIDC_CLIENT_PARAMS, indirect=True) |
133 | 182 |
@pytest.mark.parametrize('do_not_ask_again', [(True,), (False,)]) |
134 | 183 |
@pytest.mark.parametrize('login_first', [(True,), (False,)]) |
135 |
- |