1 #!/usr/bin/env python 2 # -*- coding: iso-8859-1 -*- 3 4 "An OpenID login provider." 5 6 # Site map imports. 7 8 from WebStack.Generic import ContentType 9 from WebStack.Resources.OpenIDLogin import Authenticator 10 from WebStack.Resources.ResourceMap import MapResource 11 from WebStack.Resources.Selectors import EncodingSelector, PathSelector 12 from WebStack.Resources.Static import StringResource 13 import XSLForms.Resources.OpenIDLogin 14 from XSLForms.Resources.WebResources import output, prepare_resources as pr, resources 15 16 # Configuration settings. 17 18 encoding = "utf-8" 19 20 # Resource classes. 21 22 class LoginResource(XSLForms.Resources.OpenIDLogin.OpenIDLoginResource): 23 24 "Special login screen for this application." 25 26 resource_dir = resources(__file__) 27 template_resources = { 28 "login" : output("login_template.xhtml"), 29 "success" : output("success_template.xhtml") 30 } 31 32 # Site map initialisation. 33 34 def get_site(host, use_redirect=1): 35 36 "Return a simple Web site resource." 37 38 # Authentication objects. 39 40 credentials = [ 41 ((host + "/badger", "badger"), "abc"), 42 ((host + "/vole", "vole"), "xyz"), 43 ((host + u"/???", u"???"), u"???") 44 ] 45 login_authenticator = Authenticator(credentials) 46 47 # Get a login resource. 48 49 login_resource = LoginResource(host, login_authenticator, use_redirect=use_redirect) 50 51 # A container for the login resource and user pages. 52 53 resource = MapResource({ 54 "login" : login_resource, 55 56 # Some local OpenID pages. 57 58 "badger" : 59 StringResource(""" 60 <html> 61 <head> 62 <link rel="openid2.provider openid.server" href="%s/login" /> 63 <link rel="openid2.local_id openid.delegate" href="%s/badger" /> 64 <title>Badger's Home Page</title> 65 </head> 66 <body> 67 <p>Home page for the OpenID authenticated user, <code>badger</code>.</p> 68 </body> 69 </html> 70 """ % (host, host), ContentType("text/html")), 71 u"???" : 72 StringResource(u""" 73 <html> 74 <head> 75 <link rel="openid2.provider openid.server" href="%s/login" /> 76 <link rel="openid2.local_id openid.delegate" href="%s/???" /> 77 <title>Home Page for ???</title> 78 </head> 79 <body> 80 <p>Home page for the OpenID authenticated user, <code>???</code>.</p> 81 </body> 82 </html> 83 """ % (host, host), ContentType("text/html", "iso-8859-1")), 84 "vole" : 85 StringResource(""" 86 <html> 87 <head> 88 <link rel="openid2.provider openid.server" href="%s/login" /> 89 <link rel="openid2.local_id openid.delegate" href="%s/vole" /> 90 <title>Vole's Home Page</title> 91 </head> 92 <body> 93 <p>Home page for the OpenID authenticated user, <code>vole</code>.</p> 94 </body> 95 </html> 96 """ % (host, host), ContentType("text/html")) 97 }) 98 99 # Wrap the resource up with information about the application root. 100 101 return EncodingSelector(PathSelector(resource), encoding) 102 103 # Resource preparation ahead of time - useful for making installations. 104 105 def prepare_resources(): 106 for cls in [LoginResource]: 107 pr(cls) 108 109 # vim: tabstop=4 expandtab shiftwidth=4