diff examples/turbogears/markuptest/controllers.py @ 110:64ff134868c4 trunk

update the example TurboGears app and include an example of using TurboGears wigets
author mgood
date Fri, 28 Jul 2006 18:57:55 +0000
parents 49364e784c47
children
line wrap: on
line diff
--- a/examples/turbogears/markuptest/controllers.py
+++ b/examples/turbogears/markuptest/controllers.py
@@ -3,7 +3,8 @@
 import cherrypy
 
 import turbogears
-from turbogears import controllers, expose, validate, redirect
+from turbogears import controllers, expose, validate, redirect, widgets
+from turbogears import identity
 
 from markuptest import json
 
@@ -14,4 +15,40 @@
     def index(self):
         import time
         log.debug("Happy TurboGears Controller Responding For Duty")
-        return dict(now=time.ctime())
+        return dict(now=time.ctime(),
+                    widget=widgets.TextArea(name="widget_test",
+                                            default="This is a test of using "
+                                                    "TurboGears widgets with "
+                                                    "Markup",
+                                            rows=5, cols=40))
+
+
+    @expose(template="markuptest.templates.login")
+    def login(self, forward_url=None, previous_url=None, *args, **kw):
+
+        if not identity.current.anonymous \
+            and identity.was_login_attempted() \
+            and not identity.get_identity_errors():
+            raise redirect(forward_url)
+
+        forward_url=None
+        previous_url= cherrypy.request.path
+
+        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.")
+            forward_url= cherrypy.request.headers.get("Referer", "/")
+        cherrypy.response.status=403
+        return dict(message=msg, previous_url=previous_url, logging_in=True,
+                    original_parameters=cherrypy.request.params,
+                    forward_url=forward_url)
+
+    @expose()
+    def logout(self):
+        identity.current.logout()
+        raise redirect("/")
Copyright (C) 2012-2017 Edgewall Software