# HG changeset patch # User paulb # Date 1085871988 0 # Node ID ef59d738a382dbfd15c0a82b7efeeb5a63b33809 # Parent b3e008dd2f9faafe93125da658e1c4f4afb5ff40 [project @ 2004-05-29 23:06:28 by paulb] Added a success screen for mod_python, which won't allow redirects and cookies in the same transaction. diff -r b3e008dd2f9f -r ef59d738a382 examples/Common/Login/__init__.py --- a/examples/Common/Login/__init__.py Sat May 29 23:05:46 2004 +0000 +++ b/examples/Common/Login/__init__.py Sat May 29 23:06:28 2004 +0000 @@ -9,11 +9,16 @@ "A resource providing a login screen." - def __init__(self, authenticator): + def __init__(self, authenticator, use_redirect=1): - "Initialise the resource with an 'authenticator'." + """ + Initialise the resource with an 'authenticator'. If the optional 'use_redirect' + flag is set to 0, a confirmation screen is given instead of redirecting the user + back to the original application. + """ self.authenticator = authenticator + self.use_redirect = use_redirect def respond(self, trans): @@ -24,15 +29,23 @@ redirects = fields["redirect"] redirect = redirects[0] if self.authenticator.authenticate(trans): - trans.set_header_value("Location", redirect) - trans.set_response_code(307) - return + if self.use_redirect: + trans.set_header_value("Location", redirect) + trans.set_response_code(307) + return + else: + self._show_success(trans, redirect) + return else: fields = trans.get_fields_from_path() if fields.has_key("redirect"): redirects = fields["redirect"] redirect = redirects[0] + self._show_login(trans, redirect) + + def _show_login(self, trans, redirect): + # When authentication fails or is yet to take place, show the login # screen. @@ -55,6 +68,25 @@ """ % redirect) + def _show_success(self, trans, redirect): + + # When authentication fails or is yet to take place, show the login + # screen. + + trans.set_content_type(WebStack.Generic.ContentType("text/html")) + out = trans.get_response_stream() + out.write(""" + + + Login Example + + +

Login Successful

+

Please proceed to the application.

+ + +""" % redirect) + def _decode(self, url): "Decode the given 'url' for redirection purposes."