# HG changeset patch # User paulb # Date 1085931190 0 # Node ID b995d1bfbb693ce07c9359f83c3fc31a00c167b1 # Parent 92ee650c509dcb19c3ee2398b5f44c9b7e22b32e [project @ 2004-05-30 15:33:10 by paulb] Added authentication cookies for anonymous users (using a redirect to the login application). Changed token construction to use WebStack.Helpers.Auth.get_token. diff -r 92ee650c509d -r b995d1bfbb69 examples/Common/LoginRedirect/__init__.py --- a/examples/Common/LoginRedirect/__init__.py Sun May 30 15:32:29 2004 +0000 +++ b/examples/Common/LoginRedirect/__init__.py Sun May 30 15:33:10 2004 +0000 @@ -15,8 +15,8 @@ the application being protected should be reachable, and an 'authenticator'. If the optional 'anonymous_parameter_name' is set, clients providing a parameter - of that name in the URL will not be authenticated, but then such clients will not - get a user identity associated with them. + of that name in the URL will have that parameter sent specially to the login + application. """ self.login_url = login_url @@ -27,22 +27,25 @@ def respond(self, trans): - # Check for the anonymous parameter, if appropriate. - - fields = trans.get_fields_from_path() - if self.anonymous_parameter_name is not None and fields.has_key(self.anonymous_parameter_name): - is_anonymous = 1 - else: - is_anonymous = 0 - # Check the authentication details with the specified authenticator. - if is_anonymous or self.authenticator.authenticate(trans): + if self.authenticator.authenticate(trans): self.resource.respond(trans) else: + # Define anonymous mode, if appropriate. + + fields_path = trans.get_fields_from_path() + + if self.anonymous_parameter_name is not None and fields_path.has_key(self.anonymous_parameter_name): + anonymous_parameter = "%s=%s&" % (self.anonymous_parameter_name, fields_path[self.anonymous_parameter_name][0]) + else: + anonymous_parameter = "" + # Redirect to the login URL. - trans.set_header_value("Location", "%s?redirect=%s%s" % (self.login_url, self.app_url, self._encode(trans.get_path()))) + trans.set_header_value("Location", "%s?%sredirect=%s%s" % ( + self.login_url, anonymous_parameter, self.app_url, self._encode(trans.get_path())) + ) trans.set_response_code(307) def _encode(self, url):