vigiboard / vigiboard / controllers / vigiboard_controller.py @ 870b9bb7
History | View | Annotate | Download (2.26 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4:
|
3 |
"""
|
4 |
Controller for authentification
|
5 |
"""
|
6 |
|
7 |
from tg import expose, flash, request, redirect |
8 |
|
9 |
from pylons.i18n import ugettext as _ |
10 |
|
11 |
from vigilo.models import ApplicationLog |
12 |
|
13 |
from vigiboard.lib.base import BaseController |
14 |
from vigiboard.controllers.error import ErrorController |
15 |
|
16 |
# pylint: disable-msg=R0201
|
17 |
class VigiboardRootController(BaseController): |
18 |
"""
|
19 |
The root controller for the vigiboard application.
|
20 |
|
21 |
All the other controllers and WSGI applications should be mounted on this
|
22 |
controller. For example::
|
23 |
|
24 |
panel = ControlPanelController()
|
25 |
another_app = AnotherWSGIApplication()
|
26 |
|
27 |
Keep in mind that WSGI applications shouldn't be mounted directly: They
|
28 |
must be wrapped around with :class:`tg.controllers.WSGIAppController`.
|
29 |
"""
|
30 |
|
31 |
error = ErrorController() |
32 |
|
33 |
@expose('login.html') |
34 |
def login(self, came_from='/'): |
35 |
"""Start the user login."""
|
36 |
login_counter = request.environ['repoze.who.logins']
|
37 |
if login_counter > 0: |
38 |
flash(_('Wrong credentials'), 'warning') |
39 |
return dict(page='login', login_counter=str(login_counter), |
40 |
came_from=came_from) |
41 |
|
42 |
@expose()
|
43 |
def post_login(self, came_from='/'): |
44 |
"""
|
45 |
Redirect the user to the initially requested page on successful
|
46 |
authentication or redirect her back to the login page if login failed.
|
47 |
"""
|
48 |
if not request.identity: |
49 |
login_counter = request.environ['repoze.who.logins'] + 1 |
50 |
redirect('/login', came_from=came_from, __logins=login_counter)
|
51 |
userid = request.identity['repoze.who.userid']
|
52 |
ApplicationLog.add_login(userid, request.remote_addr, u'Vigiboard')
|
53 |
flash(_('Welcome back, %s!') % userid)
|
54 |
redirect(came_from) |
55 |
|
56 |
@expose()
|
57 |
def post_logout(self, came_from='/'): |
58 |
"""
|
59 |
Redirect the user to the initially requested page on logout and say
|
60 |
goodbye as well.
|
61 |
"""
|
62 |
# XXX Ne fonctionne pas, l'identité est déjà oubliée arrivé ici.
|
63 |
# userid = request.identity['repoze.who.userid']
|
64 |
# ApplicationLog.add_logout(userid, request.remote_addr, u'Vigiboard')
|
65 |
flash(_('We hope to see you soon!'))
|
66 |
redirect(came_from) |
67 |
|