1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/BaseHTTPRequestHandler/OpenIDLoginApp.py Mon Nov 19 00:18:43 2007 +0000
1.3 @@ -0,0 +1,16 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +from WebStack.Adapters.BaseHTTPRequestHandler import deploy
1.7 +import OpenIDLogin
1.8 +
1.9 +# Get a simple Web site.
1.10 +
1.11 +host = "http://localhost:8081" # Without trailing "/"!
1.12 +resource = OpenIDLogin.get_site(host)
1.13 +
1.14 +# Special magic incantation.
1.15 +
1.16 +print "Serving..."
1.17 +deploy(resource, handle_errors=0, address=("", 8081)) # NOTE: Change when host changes!
1.18 +
1.19 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/Common/OpenIDLogin/Resources/login_template.xhtml Mon Nov 19 00:18:43 2007 +0000
2.3 @@ -0,0 +1,46 @@
2.4 +<?xml version="1.0" encoding="iso-8859-1"?>
2.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
2.7 +<html xmlns="http://www.w3.org/1999/xhtml"
2.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
2.9 +<head>
2.10 + <title>Login</title>
2.11 +</head>
2.12 +
2.13 +<body template:element="login">
2.14 +<h1>Login</h1>
2.15 +
2.16 +<form method="post">
2.17 + <table cellspacing="0" cellpadding="5" id="login-info">
2.18 + <thead>
2.19 + <tr>
2.20 + <th class="heading" colspan="2">Login</th>
2.21 + </tr>
2.22 + </thead>
2.23 + <tbody>
2.24 + <tr template:element="error" template:init="no">
2.25 + <th>Error</th>
2.26 + <td><span template:attribute-area="message,replace">error message</span></td>
2.27 + </tr>
2.28 + <tr>
2.29 + <th>Username</th>
2.30 + <td><input type="text" template:attribute-field="username" name="..." value="..." size="20"/></td>
2.31 + </tr>
2.32 + <tr>
2.33 + <th>Password</th>
2.34 + <td><input type="password" template:attribute-field="password" name="..." value="..." size="20"/></td>
2.35 + </tr>
2.36 + <tr>
2.37 + <td colspan="2">
2.38 + <input type="submit" value="Log in!" name="login" />
2.39 + </td>
2.40 + </tr>
2.41 + </tbody>
2.42 + </table>
2.43 + <input type="hidden" template:attribute-field="return_to" name="..." value="..."/>
2.44 + <input type="hidden" template:attribute-field="claimed_id" name="..." value="..."/>
2.45 + <input type="hidden" template:attribute-field="identity" name="..." value="..."/>
2.46 +</form>
2.47 +
2.48 +</body>
2.49 +</html>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/examples/Common/OpenIDLogin/Resources/success_template.xhtml Mon Nov 19 00:18:43 2007 +0000
3.3 @@ -0,0 +1,19 @@
3.4 +<?xml version="1.0" encoding="iso-8859-1"?>
3.5 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3.6 + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3.7 +<html xmlns="http://www.w3.org/1999/xhtml"
3.8 + xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
3.9 +<head>
3.10 + <title>Very Simple Login Succeeded</title>
3.11 +</head>
3.12 +
3.13 +<body template:element="success">
3.14 +<h1>Login Successful</h1>
3.15 +
3.16 + <form action="{@location}" method="POST" name="openid_redirect">
3.17 + <input template:element="field" name="{@name}" type="hidden" value="{@value}" />
3.18 + <p>Please proceed to the application: <input name="proceed" type="submit" value="Proceed!" /></p>
3.19 + </form>
3.20 +
3.21 +</body>
3.22 +</html>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/examples/Common/OpenIDLogin/__init__.py Mon Nov 19 00:18:43 2007 +0000
4.3 @@ -0,0 +1,94 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +"An OpenID login provider."
4.7 +
4.8 +# Site map imports.
4.9 +
4.10 +from WebStack.Generic import ContentType
4.11 +from WebStack.Resources.OpenIDLogin import Authenticator
4.12 +from WebStack.Resources.ResourceMap import MapResource
4.13 +from WebStack.Resources.Selectors import EncodingSelector, PathSelector
4.14 +from WebStack.Resources.Static import StringResource
4.15 +import XSLForms.Resources.OpenIDLogin
4.16 +from XSLForms.Resources.WebResources import output, prepare_resources as pr, resources
4.17 +
4.18 +# Configuration settings.
4.19 +
4.20 +encoding = "utf-8"
4.21 +
4.22 +# Resource classes.
4.23 +
4.24 +class LoginResource(XSLForms.Resources.OpenIDLogin.OpenIDLoginResource):
4.25 +
4.26 + "Special login screen for this application."
4.27 +
4.28 + resource_dir = resources(__file__)
4.29 + template_resources = {
4.30 + "login" : output("login_template.xhtml"),
4.31 + "success" : output("success_template.xhtml")
4.32 + }
4.33 +
4.34 +# Site map initialisation.
4.35 +
4.36 +def get_site(host, use_redirect=1):
4.37 +
4.38 + "Return a simple Web site resource."
4.39 +
4.40 + # Authentication objects.
4.41 +
4.42 + credentials = [
4.43 + ((host + "/badger", "badger"), "abc"),
4.44 + ((host + "/vole", "vole"), "xyz")
4.45 + ]
4.46 + login_authenticator = Authenticator(credentials)
4.47 +
4.48 + # Get a login resource.
4.49 +
4.50 + login_resource = LoginResource(host, login_authenticator, use_redirect=use_redirect)
4.51 +
4.52 + # A container for the login resource and user pages.
4.53 +
4.54 + resource = MapResource({
4.55 + "login" : login_resource,
4.56 +
4.57 + # Some local OpenID pages.
4.58 +
4.59 + "badger" :
4.60 + StringResource("""
4.61 + <html>
4.62 + <head>
4.63 + <link rel="openid2.provider openid.server" href="%s/login" />
4.64 + <link rel="openid2.local_id openid.delegate" href="%s/badger" />
4.65 + <title>Badger's Home Page</title>
4.66 + </head>
4.67 + <body>
4.68 + <p>Home page for the OpenID authenticated user, <code>badger</code>.</p>
4.69 + </body>
4.70 + </html>
4.71 + """ % (host, host), ContentType("text/html")),
4.72 + "vole" :
4.73 + StringResource("""
4.74 + <html>
4.75 + <head>
4.76 + <link rel="openid2.provider openid.server" href="%s/login" />
4.77 + <link rel="openid2.local_id openid.delegate" href="%s/vole" />
4.78 + <title>Vole's Home Page</title>
4.79 + </head>
4.80 + <body>
4.81 + <p>Home page for the OpenID authenticated user, <code>vole</code>.</p>
4.82 + </body>
4.83 + </html>
4.84 + """ % (host, host), ContentType("text/html"))
4.85 + })
4.86 +
4.87 + # Wrap the resource up with information about the application root.
4.88 +
4.89 + return EncodingSelector(PathSelector(resource), encoding)
4.90 +
4.91 +# Resource preparation ahead of time - useful for making installations.
4.92 +
4.93 +def prepare_resources():
4.94 + for cls in [LoginResource]:
4.95 + pr(cls)
4.96 +
4.97 +# vim: tabstop=4 expandtab shiftwidth=4