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