# HG changeset patch # User paulb # Date 1076276589 0 # Node ID 31814646dc1f409dae26af805b387b68761ee5e4 # Parent a872e47ad6b3f38c17672685a611546093267ebf [project @ 2004-02-08 21:43:09 by paulb] Added an authentication/authorisation example. diff -r a872e47ad6b3 -r 31814646dc1f examples/Common/Auth/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/Auth/__init__.py Sun Feb 08 21:43:09 2004 +0000 @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +"A test of authentication/authorisation." + +import WebStack.Generic + +class AuthResource: + + "A resource demanding authentication." + + def respond(self, trans): + user = trans.get_user() + if user is None: + trans.set_response_code(401) + trans.set_header("WWW-Authenticate", 'Basic realm="AuthResource"') + return + + trans.set_content_type(WebStack.Generic.ContentType("text/html")) + + # Write out confirmation, otherwise. + + out = trans.get_response_stream() + out.write(""" + + +

Authorised

+

Hello user %s!

+ + +""" % ( + user, +)) + +# vim: tabstop=4 expandtab shiftwidth=4