cmlenz@4: import logging cmlenz@4: cmlenz@4: import cherrypy cmlenz@4: cmlenz@4: import turbogears mgood@110: from turbogears import controllers, expose, validate, redirect, widgets mgood@110: from turbogears import identity cmlenz@4: cmlenz@230: from genshitest import json cmlenz@4: cmlenz@230: log = logging.getLogger("genshitest.controllers") cmlenz@4: cmlenz@4: class Root(controllers.RootController): cmlenz@262: cmlenz@230: @expose(template="genshitest.templates.welcome") cmlenz@4: def index(self): cmlenz@4: import time cmlenz@4: log.debug("Happy TurboGears Controller Responding For Duty") mgood@110: return dict(now=time.ctime(), mgood@110: widget=widgets.TextArea(name="widget_test", mgood@110: default="This is a test of using " mgood@110: "TurboGears widgets with " cmlenz@230: "Genshi", mgood@110: rows=5, cols=40)) mgood@110: cmlenz@265: @expose(template="genshi-text:genshitest.templates.plain", cmlenz@265: content_type='text/plain; charset=utf-8') cmlenz@265: def plain(self): cmlenz@265: return dict(name='world') cmlenz@265: cmlenz@230: @expose(template="genshitest.templates.login") mgood@110: def login(self, forward_url=None, previous_url=None, *args, **kw): mgood@110: mgood@110: if not identity.current.anonymous \ mgood@110: and identity.was_login_attempted() \ mgood@110: and not identity.get_identity_errors(): mgood@110: raise redirect(forward_url) mgood@110: mgood@110: forward_url=None mgood@110: previous_url= cherrypy.request.path mgood@110: mgood@110: if identity.was_login_attempted(): mgood@110: msg=_("The credentials you supplied were not correct or " mgood@110: "did not grant access to this resource.") mgood@110: elif identity.get_identity_errors(): mgood@110: msg=_("You must provide your credentials before accessing " mgood@110: "this resource.") mgood@110: else: mgood@110: msg=_("Please log in.") mgood@110: forward_url= cherrypy.request.headers.get("Referer", "/") mgood@110: cherrypy.response.status=403 mgood@110: return dict(message=msg, previous_url=previous_url, logging_in=True, mgood@110: original_parameters=cherrypy.request.params, mgood@110: forward_url=forward_url) mgood@110: mgood@110: @expose() mgood@110: def logout(self): mgood@110: identity.current.logout() mgood@110: raise redirect("/")