Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / vigiboard_controller.py @ 7365fb51

History | View | Annotate | Download (2.37 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, require, url, request, redirect
8

    
9
from pylons.i18n import ugettext as _, lazy_ugettext as l_
10
from repoze.what import predicates
11

    
12
from vigilo.models.session import DBSession
13
from vigilo.models import ApplicationLog
14

    
15
from vigiboard.lib.base import BaseController
16
from vigiboard.controllers.error import ErrorController
17

    
18
class VigiboardRootController(BaseController):
19
    """
20
    The root controller for the vigiboard application.
21
    
22
    All the other controllers and WSGI applications should be mounted on this
23
    controller. For example::
24
    
25
        panel = ControlPanelController()
26
        another_app = AnotherWSGIApplication()
27
    
28
    Keep in mind that WSGI applications shouldn't be mounted directly: They
29
    must be wrapped around with :class:`tg.controllers.WSGIAppController`.
30
    """
31

    
32
    error = ErrorController()
33

    
34
    @expose('login.html')
35
    def login(self, came_from=url('/')):
36
        """Start the user login."""
37
        login_counter = request.environ['repoze.who.logins']
38
        if login_counter > 0:
39
            flash(_('Wrong credentials'), 'warning')
40
        return dict(page='login', login_counter=str(login_counter),
41
                    came_from=came_from)
42

    
43
    @expose()
44
    def post_login(self, came_from=url('/')):
45
        """
46
        Redirect the user to the initially requested page on successful
47
        authentication or redirect her back to the login page if login failed.
48
        """
49
        if not request.identity:
50
            login_counter = request.environ['repoze.who.logins'] + 1
51
            redirect(url('/login', came_from=came_from, __logins=login_counter))
52
        userid = request.identity['repoze.who.userid']
53
        ApplicationLog.add_login(userid, request.remote_addr, u'Vigiboard')
54
        flash(_('Welcome back, %s!') % userid)
55
        redirect(came_from)
56

    
57
    @expose()
58
    def post_logout(self, came_from=url('/')):
59
        """
60
        Redirect the user to the initially requested page on logout and say
61
        goodbye as well.
62
        """
63
        # XXX Ne fonctionne pas, l'identité est déjà oubliée arrivé ici.
64
#        userid = request.identity['repoze.who.userid']
65
#        ApplicationLog.add_logout(userid, request.remote_addr, u'Vigiboard')
66
        flash(_('We hope to see you soon!'))
67
        redirect(came_from)
68