3 # Copyright (C) 2013 Simo Sorce <simo@redhat.com>
5 # see file 'COPYING' for use and warranty information
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 if cherrypy.request.login:
25 user = cherrypy.session.get('user', None)
26 if user == cherrypy.request.login:
29 cherrypy.session.regenerate()
30 cherrypy.session['user'] = cherrypy.request.login
33 def __init__(self, template_env):
34 self._env = template_env
35 self.basepath = cherrypy.config.get('base.mount', "")
38 def __call__(self, *args, **kwargs):
39 self.username = cherrypy.session.get('user', None)
40 self.user = user.User(self.username)
43 op = getattr(self, args[0], None)
44 if callable(op) and getattr(self, args[0]+'.exposed', None):
45 return op(args[1:], **kwargs)
47 op = getattr(self, 'root', None)
51 return self.default(*args, **kwargs)
53 def _template(self, *args, **kwargs):
54 t = self._env.get_template(args[0])
55 return t.render(basepath=self.basepath, user=self.user, **kwargs)
57 def default(self, *args, **kwargs):
58 raise cherrypy.HTTPError(404)