Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / vigiboard_controller.py @ 5f2cd70a

History | View | Annotate | Download (2.07 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 vigiboard.lib.base import BaseController
13
from vigiboard.model import DBSession 
14
from vigiboard.controllers.error import ErrorController
15
from vigiboard import model
16

    
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=url('/')):
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=url('/')):
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(url('/login', came_from=came_from, __logins=login_counter))
51
        userid = request.identity['repoze.who.userid']
52
        flash(_('Welcome back, %s!') % userid)
53
        redirect(came_from)
54

    
55
    @expose()
56
    def post_logout(self, came_from=url('/')):
57
        """
58
        Redirect the user to the initially requested page on logout and say
59
        goodbye as well.
60
        """
61
        flash(_('We hope to see you soon!'))
62
        redirect(came_from)
63