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