source: gutenbach-web/root.py @ 973dd91

debianmacno-cupsweb
Last change on this file since 973dd91 was 973dd91, checked in by Edward Z. Yang <edwardzyang@…>, 16 years ago

Initial commit.

Signed-off-by: Edward Z. Yang <edwardzyang@…>

  • Property mode set to 100644
File size: 2.1 KB
Line 
1"""Main Controller"""
2from sipbmp3web.lib.base import BaseController
3from tg import expose, flash, require, url, request, redirect
4from pylons.i18n import ugettext as _
5#from tg import redirect, validate
6from sipbmp3web.model import DBSession, metadata
7from sipbmp3web.controllers.error import ErrorController
8from sipbmp3web import model
9from catwalk.tg2 import Catwalk
10from repoze.what import predicates
11from sipbmp3web.controllers.secure import SecureController
12
13class RootController(BaseController):
14    admin = Catwalk(model, DBSession)
15    error = ErrorController()
16
17    @expose('sipbmp3web.templates.index')
18    def index(self):
19        return dict(page='index')
20
21    @expose('sipbmp3web.templates.about')
22    def about(self):
23        return dict(page='about')
24
25    @expose('sipbmp3web.templates.authentication')
26    def auth(self):
27        return dict(page='auth')
28
29    @expose('sipbmp3web.templates.index')
30    @require(predicates.has_permission('manage', msg=_('Only for managers')))
31    def manage_permission_only(self, **kw):
32        return dict(page='managers stuff')
33
34    @expose('sipbmp3web.templates.index')
35    @require(predicates.is_user('editor', msg=_('Only for the editor')))
36    def editor_user_only(self, **kw):
37        return dict(page='editor stuff')
38
39    @expose('sipbmp3web.templates.login')
40    def login(self, came_from=url('/')):
41        login_counter = request.environ['repoze.who.logins']
42        if login_counter > 0:
43            flash(_('Wrong credentials'), 'warning')
44        return dict(page='login', login_counter=str(login_counter),
45                    came_from=came_from)
46
47    @expose()
48    def post_login(self, came_from=url('/')):
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        flash(_('Welcome back, %s!') % userid)
54        redirect(came_from)
55
56    @expose()
57    def post_logout(self, came_from=url('/')):
58        flash(_('We hope to see you soon!'))
59        redirect(came_from)
Note: See TracBrowser for help on using the repository browser.