1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/Auth/__init__.py Sun Feb 08 21:43:09 2004 +0000
1.3 @@ -0,0 +1,34 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"A test of authentication/authorisation."
1.7 +
1.8 +import WebStack.Generic
1.9 +
1.10 +class AuthResource:
1.11 +
1.12 + "A resource demanding authentication."
1.13 +
1.14 + def respond(self, trans):
1.15 + user = trans.get_user()
1.16 + if user is None:
1.17 + trans.set_response_code(401)
1.18 + trans.set_header("WWW-Authenticate", 'Basic realm="AuthResource"')
1.19 + return
1.20 +
1.21 + trans.set_content_type(WebStack.Generic.ContentType("text/html"))
1.22 +
1.23 + # Write out confirmation, otherwise.
1.24 +
1.25 + out = trans.get_response_stream()
1.26 + out.write("""
1.27 +<html>
1.28 + <body>
1.29 + <h1>Authorised</h1>
1.30 + <p>Hello user %s!</p>
1.31 + </body>
1.32 +</html>
1.33 +""" % (
1.34 + user,
1.35 +))
1.36 +
1.37 +# vim: tabstop=4 expandtab shiftwidth=4