1 #!/usr/bin/env python 2 3 "A simple Zope product." 4 5 from Simple import SimpleResource 6 from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator 7 from WebStack.Resources.Login import LoginResource, LoginAuthenticator 8 from WebStack.Resources.ResourceMap import MapResource 9 from WebStack.Adapters.Zope import WebStackAdapterProduct 10 from Globals import InitializeClass 11 12 # NOTE: Make sure this URL matches your Zope configuration. 13 14 server_url = "http://localhost:9080" 15 16 class SimpleWithLoginProduct(WebStackAdapterProduct): 17 18 meta_type = "Simple with login product" 19 20 def __init__(self, id, parent_url): 21 WebStackAdapterProduct.__init__(self, id, 22 MapResource({ 23 "simple" : 24 LoginRedirectResource( 25 login_url=parent_url + "/" + id + "/login", 26 app_url=server_url, 27 resource=SimpleResource(), 28 authenticator=LoginRedirectAuthenticator(secret_key="horses"), 29 anonymous_parameter_name="anonymous", 30 logout_parameter_name="logout" 31 ), 32 "login" : 33 LoginResource( 34 LoginAuthenticator( 35 secret_key="horses", 36 credentials=( 37 ("badger", "abc"), 38 ("vole", "xyz"), 39 ) 40 ) 41 ) 42 }) 43 ) 44 45 InitializeClass(SimpleWithLoginProduct) 46 47 def addSimpleWithLoginProduct(self): 48 """ 49 The HTML form used to add the product. 50 """ 51 52 return """ 53 <html> 54 <head> 55 <title>Add Simple with Login Product</title> 56 </head> 57 <body> 58 <form action="addProduct"> 59 id <input name="id" type="text"><br> 60 <input name="add" type="submit" value="Add!"> 61 </form> 62 </body> 63 </html> 64 """ 65 66 def addProduct(self, id, REQUEST=None): 67 """ 68 The function used to add the product. 69 """ 70 71 product = SimpleWithLoginProduct(id, self.DestinationURL()) 72 self.Destination()._setObject(id, product) 73 if REQUEST: 74 return self.manage_main(self, REQUEST) 75 76 def initialize(context): 77 context.registerClass( 78 SimpleWithLoginProduct, 79 constructors = (addSimpleWithLoginProduct, addProduct) 80 ) 81 82 # vim: tabstop=4 expandtab shiftwidth=4