Projet

Général

Profil

0001-templates-add-a-login-template.patch

Nicolas Roche, 18 mars 2020 09:19

Télécharger (3,4 ko)

Voir les différences:

Subject: [PATCH] templates: add a login template (#)

 tests/test_manager.py            | 48 ++++++++++++++++++++++++++++++++
 welco/templates/welco/login.html |  9 ++++++
 welco/views.py                   |  2 +-
 3 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 tests/test_manager.py
 create mode 100644 welco/templates/welco/login.html
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

  
3
{% block content %}
4
<form method="post">
5
	{% csrf_token %}
6
	{{ form }}
7
	<input type="submit" name="Login"/>
8
</form>
9
{% 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
-