1.1 --- a/examples/Common/Login/__init__.py Sat May 29 23:05:46 2004 +0000
1.2 +++ b/examples/Common/Login/__init__.py Sat May 29 23:06:28 2004 +0000
1.3 @@ -9,11 +9,16 @@
1.4
1.5 "A resource providing a login screen."
1.6
1.7 - def __init__(self, authenticator):
1.8 + def __init__(self, authenticator, use_redirect=1):
1.9
1.10 - "Initialise the resource with an 'authenticator'."
1.11 + """
1.12 + Initialise the resource with an 'authenticator'. If the optional 'use_redirect'
1.13 + flag is set to 0, a confirmation screen is given instead of redirecting the user
1.14 + back to the original application.
1.15 + """
1.16
1.17 self.authenticator = authenticator
1.18 + self.use_redirect = use_redirect
1.19
1.20 def respond(self, trans):
1.21
1.22 @@ -24,15 +29,23 @@
1.23 redirects = fields["redirect"]
1.24 redirect = redirects[0]
1.25 if self.authenticator.authenticate(trans):
1.26 - trans.set_header_value("Location", redirect)
1.27 - trans.set_response_code(307)
1.28 - return
1.29 + if self.use_redirect:
1.30 + trans.set_header_value("Location", redirect)
1.31 + trans.set_response_code(307)
1.32 + return
1.33 + else:
1.34 + self._show_success(trans, redirect)
1.35 + return
1.36 else:
1.37 fields = trans.get_fields_from_path()
1.38 if fields.has_key("redirect"):
1.39 redirects = fields["redirect"]
1.40 redirect = redirects[0]
1.41
1.42 + self._show_login(trans, redirect)
1.43 +
1.44 + def _show_login(self, trans, redirect):
1.45 +
1.46 # When authentication fails or is yet to take place, show the login
1.47 # screen.
1.48
1.49 @@ -55,6 +68,25 @@
1.50 </html>
1.51 """ % redirect)
1.52
1.53 + def _show_success(self, trans, redirect):
1.54 +
1.55 + # When authentication fails or is yet to take place, show the login
1.56 + # screen.
1.57 +
1.58 + trans.set_content_type(WebStack.Generic.ContentType("text/html"))
1.59 + out = trans.get_response_stream()
1.60 + out.write("""
1.61 +<html>
1.62 + <head>
1.63 + <title>Login Example</title>
1.64 + </head>
1.65 + <body>
1.66 + <h1>Login Successful</h1>
1.67 + <p>Please proceed <a href="%s">to the application</a>.</p>
1.68 + </body>
1.69 +</html>
1.70 +""" % redirect)
1.71 +
1.72 def _decode(self, url):
1.73
1.74 "Decode the given 'url' for redirection purposes."