# HG changeset patch # User paulb # Date 1085872028 0 # Node ID 26756097a69a67b216b1d7a3a79fc0c3c797784a # Parent ef59d738a382dbfd15c0a82b7efeeb5a63b33809 [project @ 2004-05-29 23:06:55 by paulb] Added login examples. diff -r ef59d738a382 -r 26756097a69a examples/CGI/LoginHandler.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/CGI/LoginHandler.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +# NOTE: Path manipulation requires manual customisation. + +import sys +sys.path.append("/home/paulb/Software/Python/WebStack") +sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") + +from WebStack.Adapters import CGI +from Login import LoginResource, LoginAuthenticator + +resource = LoginResource( + LoginAuthenticator( + secret_key="horses", + credentials=( + ("badger", "abc"), + ("vole", "xyz"), + ) + ) +) +CGI.respond(resource) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/CGI/SimpleWithLoginHandler.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/CGI/SimpleWithLoginHandler.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +# NOTE: Path manipulation requires manual customisation. + +import sys +sys.path.append("/home/paulb/Software/Python/WebStack") +sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") + +from WebStack.Adapters import CGI +from Simple import SimpleResource +from LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator + +resource = LoginRedirectResource( + login_url="http://localhost/cgi/login", + app_url="http://localhost", + resource=SimpleResource(), + authenticator=LoginRedirectAuthenticator(secret_key="horses"), + anonymous_parameter_name="anonymous" +) +CGI.respond(resource) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/ModPython/LoginApp/LoginHandler.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/ModPython/LoginApp/LoginHandler.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +# NOTE: Path manipulation requires manual customisation. + +import sys +sys.path.append("/home/paulb/Software/Python/WebStack") +sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") + +from WebStack.Adapters import ModPython +from Login import LoginResource, LoginAuthenticator + +# NOTE: Not sure if the resource should be maintained in a resource pool. + +resource = LoginResource( + LoginAuthenticator( + secret_key="horses", + credentials=( + ("badger", "abc"), + ("vole", "xyz"), + ) + ), + use_redirect=0 +) + +def handler(req): + global resource + return ModPython.respond(req, resource, debug=1) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/ModPython/SimpleWithLoginApp/SimpleWithLoginHandler.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/ModPython/SimpleWithLoginApp/SimpleWithLoginHandler.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +# NOTE: Path manipulation requires manual customisation. + +import sys +sys.path.append("/home/paulb/Software/Python/WebStack") +sys.path.append("/home/paulb/Software/Python/WebStack/examples/Common") + +from WebStack.Adapters import ModPython +from Simple import SimpleResource +from LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator + +# NOTE: Not sure if the resource should be maintained in a resource pool. + +resource = LoginRedirectResource( + login_url="http://localhost/login/app.login", + app_url="http://localhost", + resource=SimpleResource(), + authenticator=LoginRedirectAuthenticator(secret_key="horses"), + anonymous_parameter_name="anonymous" +) + +def handler(req): + global resource + return ModPython.respond(req, resource, debug=1) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/Twisted/LoginApp.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Twisted/LoginApp.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +from WebStack.Adapters import Twisted +from Login import LoginResource, LoginAuthenticator +import twisted.web.server +import twisted.internet.reactor + +# Special magic incantation. + +resource = LoginResource( + LoginAuthenticator( + secret_key="horses", + credentials=( + ("badger", "abc"), + ("vole", "xyz"), + ) + ) +) + +top_level = Twisted.Dispatcher(resource) +site = twisted.web.server.Site(top_level) +twisted.internet.reactor.listenTCP(8081, site) +twisted.internet.reactor.run() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/Twisted/SimpleWithLoginApp.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Twisted/SimpleWithLoginApp.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +from WebStack.Adapters import Twisted +from Simple import SimpleResource +from LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator +import twisted.web.server +import twisted.internet.reactor + +# Special magic incantation. + +resource = LoginRedirectResource( + login_url="http://localhost:8081", + app_url="http://localhost:8080", + resource=SimpleResource(), + authenticator=LoginRedirectAuthenticator(secret_key="horses"), + anonymous_parameter_name="anonymous" +) + +top_level = Twisted.Dispatcher(resource) +site = twisted.web.server.Site(top_level) +twisted.internet.reactor.listenTCP(8080, site) +twisted.internet.reactor.run() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/Webware/LoginApp/Properties.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Webware/LoginApp/Properties.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +name = "Login" + +version = (0, 1, 0) + +status = "alpha" + +releaseDate = "?" + +requiredPyVersion = (2, 2, 0) + +synopsis = "A WebStack login application." + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/Webware/LoginApp/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Webware/LoginApp/__init__.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +""" +Webware plug-in code. +""" + +__version__ = "0.1" + +from WebStack.Adapters.Webware import WebStackServletFactory +from Login import LoginResource, LoginAuthenticator + +# NOTE: Initialising a shared resource. + +resource = LoginResource( + LoginAuthenticator( + secret_key="horses", + credentials=( + ("badger", "abc"), + ("vole", "xyz"), + ) + ) +) + +def InstallInWebKit(appServer): + global resource + app = appServer.application() + + # NOTE: Allow .login files only. Really, we'd like any kind of file, but + # NOTE: that would severely undermine the servlet factory concept. + + app.addServletFactory(WebStackServletFactory(app, resource, [".login"])) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/Webware/LoginContext/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Webware/LoginContext/__init__.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +""" +Webware context for the Login application (post Webware 0.8.1). +""" + +from WebStack.Adapters.Webware import WebStackURLParser +from Login import LoginResource, LoginAuthenticator + +# NOTE: Initialising a shared resource. + +resource = LoginResource( + LoginAuthenticator( + secret_key="horses", + credentials=( + ("badger", "abc"), + ("vole", "xyz"), + ) + ) +) + +urlParser = WebStackURLParser(resource) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/Webware/SimpleWithLoginApp/Properties.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Webware/SimpleWithLoginApp/Properties.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +name = "SimpleWithLogin" + +version = (0, 1, 0) + +status = "alpha" + +releaseDate = "?" + +requiredPyVersion = (2, 2, 0) + +synopsis = "A simple WebStack application protected by a login screen." + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/Webware/SimpleWithLoginApp/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Webware/SimpleWithLoginApp/__init__.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +""" +Webware plug-in code. +""" + +__version__ = "0.1" + +from WebStack.Adapters.Webware import WebStackServletFactory +from Simple import SimpleResource +from LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator + +# NOTE: Initialising a shared resource. + +resource = LoginRedirectResource( + login_url="http://localhost/webkit/app.login", + app_url="http://localhost", + resource=SimpleResource(), + authenticator=LoginRedirectAuthenticator(secret_key="horses"), + anonymous_parameter_name="anonymous" +) + +def InstallInWebKit(appServer): + global resource + app = appServer.application() + + # NOTE: Allow .xsimple files only. Really, we'd like any kind of file, but + # NOTE: that would severely undermine the servlet factory concept. + + app.addServletFactory(WebStackServletFactory(app, resource, [".xsimple"])) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ef59d738a382 -r 26756097a69a examples/Webware/SimpleWithLoginContext/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Webware/SimpleWithLoginContext/__init__.py Sat May 29 23:07:08 2004 +0000 @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +""" +Webware context for the Simple application (post Webware 0.8.1). +""" + +from WebStack.Adapters.Webware import WebStackURLParser +from Simple import SimpleResource +from LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator + +# NOTE: Initialising a shared resource. + +resource = LoginRedirectResource( + login_url="http://localhost/webkitcvs/login", + app_url="http://localhost", + resource=SimpleResource(), + authenticator=LoginRedirectAuthenticator(secret_key="horses"), + anonymous_parameter_name="anonymous" +) +urlParser = WebStackURLParser(resource) + +# vim: tabstop=4 expandtab shiftwidth=4