0001-templates-add-a-login-template-40802.patch
tests/test_manager.py | ||
---|---|---|
1 |
# welco - multichannel request processing |
|
2 |
# Copyright (C) 2020 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 | ||
18 |
import pytest |
|
19 | ||
20 |
def login(app, username='toto', password='toto'): |
|
21 |
login_page = app.get('/login/') |
|
22 |
login_form = login_page.forms[0] |
|
23 |
login_form['username'] = username |
|
24 |
login_form['password'] = password |
|
25 |
resp = login_form.submit() |
|
26 |
assert resp.status_int == 302 |
|
27 |
return app |
|
28 | ||
29 | ||
30 |
@pytest.fixture |
|
31 |
def logged_app(app, user): |
|
32 |
return login(app) |
|
33 | ||
34 | ||
35 |
def test_unlogged_access(app): |
|
36 |
# connect while not being logged in |
|
37 |
assert app.get('/', status=302).location.endswith('/login/?next=/') |
|
38 | ||
39 | ||
40 |
def test_access(logged_app, mail_group): |
|
41 |
resp = logged_app.get('/', status=302) |
|
42 |
assert resp.location == 'mail/' |
|
43 | ||
44 | ||
45 |
def test_logout(logged_app): |
|
46 |
app = logged_app |
|
47 |
app.get('/logout/') |
|
48 |
assert app.get('/', status=302).location.endswith('/login/?next=/') |
welco/templates/welco/login.html | ||
---|---|---|
1 |
{% extends "welco/base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block content %} |
|
5 |
<form method="post"> |
|
6 |
{% csrf_token %} |
|
7 |
{{ form }} |
|
8 |
<button>{% trans 'Log in' %}</button> |
|
9 |
</form> |
|
10 |
{% endblock %} |
welco/views.py | ||
---|---|---|
48 | 48 | |
49 | 49 | |
50 | 50 |
def login(request, *args, **kwargs): |
51 | 51 |
if any(get_idps()): |
52 | 52 |
if not 'next' in request.GET: |
53 | 53 |
return HttpResponseRedirect(resolve_url('mellon_login')) |
54 | 54 |
return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' |
55 | 55 |
+ quote(request.GET.get('next'))) |
56 |
return auth_views.login(request, *args, **kwargs)
|
|
56 |
return auth_views.login(request, template_name='welco/login.html')
|
|
57 | 57 | |
58 | 58 |
def logout(request, next_page=None): |
59 | 59 |
if any(get_idps()): |
60 | 60 |
return HttpResponseRedirect(resolve_url('mellon_logout')) |
61 | 61 |
auth_logout(request) |
62 | 62 |
if next_page is not None: |
63 | 63 |
next_page = resolve_url(next_page) |
64 | 64 |
else: |
65 |
- |