# HG changeset patch
# User paulb
# Date 1195431523 0
# Node ID 44177531fb20541e2b5846ed66cd75f9a0837c4d
# Parent 1e27f5ecaf4d0fdd94664c38c42bf75b3021c06e
[project @ 2007-11-19 00:18:35 by paulb]
Added an OpenID login example.
diff -r 1e27f5ecaf4d -r 44177531fb20 examples/BaseHTTPRequestHandler/OpenIDLoginApp.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/BaseHTTPRequestHandler/OpenIDLoginApp.py Mon Nov 19 00:18:43 2007 +0000
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+from WebStack.Adapters.BaseHTTPRequestHandler import deploy
+import OpenIDLogin
+
+# Get a simple Web site.
+
+host = "http://localhost:8081" # Without trailing "/"!
+resource = OpenIDLogin.get_site(host)
+
+# Special magic incantation.
+
+print "Serving..."
+deploy(resource, handle_errors=0, address=("", 8081)) # NOTE: Change when host changes!
+
+# vim: tabstop=4 expandtab shiftwidth=4
diff -r 1e27f5ecaf4d -r 44177531fb20 examples/Common/OpenIDLogin/Resources/login_template.xhtml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/Common/OpenIDLogin/Resources/login_template.xhtml Mon Nov 19 00:18:43 2007 +0000
@@ -0,0 +1,46 @@
+
+
+
+
+ Login
+
+
+
+Login
+
+
+
+
+
diff -r 1e27f5ecaf4d -r 44177531fb20 examples/Common/OpenIDLogin/Resources/success_template.xhtml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/Common/OpenIDLogin/Resources/success_template.xhtml Mon Nov 19 00:18:43 2007 +0000
@@ -0,0 +1,19 @@
+
+
+
+
+ Very Simple Login Succeeded
+
+
+
+Login Successful
+
+
+
+
+
diff -r 1e27f5ecaf4d -r 44177531fb20 examples/Common/OpenIDLogin/__init__.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/Common/OpenIDLogin/__init__.py Mon Nov 19 00:18:43 2007 +0000
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+
+"An OpenID login provider."
+
+# Site map imports.
+
+from WebStack.Generic import ContentType
+from WebStack.Resources.OpenIDLogin import Authenticator
+from WebStack.Resources.ResourceMap import MapResource
+from WebStack.Resources.Selectors import EncodingSelector, PathSelector
+from WebStack.Resources.Static import StringResource
+import XSLForms.Resources.OpenIDLogin
+from XSLForms.Resources.WebResources import output, prepare_resources as pr, resources
+
+# Configuration settings.
+
+encoding = "utf-8"
+
+# Resource classes.
+
+class LoginResource(XSLForms.Resources.OpenIDLogin.OpenIDLoginResource):
+
+ "Special login screen for this application."
+
+ resource_dir = resources(__file__)
+ template_resources = {
+ "login" : output("login_template.xhtml"),
+ "success" : output("success_template.xhtml")
+ }
+
+# Site map initialisation.
+
+def get_site(host, use_redirect=1):
+
+ "Return a simple Web site resource."
+
+ # Authentication objects.
+
+ credentials = [
+ ((host + "/badger", "badger"), "abc"),
+ ((host + "/vole", "vole"), "xyz")
+ ]
+ login_authenticator = Authenticator(credentials)
+
+ # Get a login resource.
+
+ login_resource = LoginResource(host, login_authenticator, use_redirect=use_redirect)
+
+ # A container for the login resource and user pages.
+
+ resource = MapResource({
+ "login" : login_resource,
+
+ # Some local OpenID pages.
+
+ "badger" :
+ StringResource("""
+
+
+
+
+ Badger's Home Page
+
+
+ Home page for the OpenID authenticated user, badger
.
+
+
+ """ % (host, host), ContentType("text/html")),
+ "vole" :
+ StringResource("""
+
+
+
+
+ Vole's Home Page
+
+
+ Home page for the OpenID authenticated user, vole
.
+
+
+ """ % (host, host), ContentType("text/html"))
+ })
+
+ # Wrap the resource up with information about the application root.
+
+ return EncodingSelector(PathSelector(resource), encoding)
+
+# Resource preparation ahead of time - useful for making installations.
+
+def prepare_resources():
+ for cls in [LoginResource]:
+ pr(cls)
+
+# vim: tabstop=4 expandtab shiftwidth=4