1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import turbogears as tg
from turbogears import controllers, expose, flash
# from israwhidebroken import model
from turbogears import identity, redirect
from cherrypy import request, response
# from israwhidebroken import json
# import logging
# log = logging.getLogger("israwhidebroken.controllers")
class Root(controllers.RootController):
@expose(template="israwhidebroken.templates.index")
# @identity.require(identity.in_group("admin"))
def index(self):
import time
# log.debug("Happy TurboGears Controller Responding For Duty")
if identity.current.anonymous:
flash("Your application is now running")
else:
flash("Welcome, %s" % identity.current.user_name)
return dict(now=time.ctime())
@expose(template="israwhidebroken.templates.login")
def login(self, forward_url=None, *args, **kw):
if forward_url:
if isinstance(forward_url, list):
forward_url = forward_url.pop(0)
else:
del request.params['forward_url']
if not identity.current.anonymous and identity.was_login_attempted() \
and not identity.get_identity_errors():
redirect(tg.url(forward_url or '/', kw))
if identity.was_login_attempted():
msg = _("The credentials you supplied were not correct or "
"did not grant access to this resource.")
elif identity.get_identity_errors():
msg = _("You must provide your credentials before accessing "
"this resource.")
else:
msg = _("Please log in.")
if not forward_url:
forward_url = request.headers.get("Referer", "/")
response.status = 401
return dict(logging_in=True, message=msg,
forward_url=forward_url, previous_url=request.path_info,
original_parameters=request.params)
@expose()
def logout(self):
identity.current.logout()
redirect("/")
|