1.1 --- a/WebStack/Resources/LoginRedirect.py Sun Aug 24 20:51:10 2008 +0200
1.2 +++ b/WebStack/Resources/LoginRedirect.py Sat Nov 15 02:33:06 2008 +0100
1.3 @@ -26,12 +26,42 @@
1.4
1.5 class LoginRedirectResource:
1.6
1.7 - "A resource redirecting to a login URL."
1.8 + """
1.9 + A resource redirecting to a login URL. A number of class attributes can be
1.10 + set or overridden by instance attributes:
1.11 +
1.12 + * anonymous_parameter_name - if set to a value other than None, clients
1.13 + providing a parameter of that name in the
1.14 + URL will not be authenticated, but then
1.15 + such clients will get a predefined user
1.16 + identity associated with them, configurable
1.17 + using 'anonymous_username'
1.18 +
1.19 + * logout_parameter_name - if set to a value other than None, clients
1.20 + providing a parameter of that name in the URL
1.21 + will become logged out; after logging out,
1.22 + clients are redirected to a location which can
1.23 + be configured by 'logout_url'
1.24
1.25 - def __init__(self, resource, authenticator, login_url=None, app_url=None,
1.26 - anonymous_parameter_name=None, anonymous_username="anonymous",
1.27 - logout_parameter_name=None, logout_url="/", use_logout_redirect=1,
1.28 - urlencoding=None, path_encoding=None):
1.29 + * use_logout_redirect - if set to 0, a confirmation screen is given
1.30 + instead of redirecting the user to 'logout_url'
1.31 +
1.32 + * path_encoding' (previously 'urlencoding') allows a special encoding to
1.33 + be used in producing the redirection path
1.34 +
1.35 + To change the page used by this resource, either redefine the
1.36 + 'logout_page' attribute in instances of this class or a subclass, or
1.37 + override the 'show_logout' method.
1.38 + """
1.39 +
1.40 + anonymous_parameter_name = None
1.41 + anonymous_username = "anonymous"
1.42 + logout_parameter_name = None
1.43 + logout_url = "/"
1.44 + use_logout_redirect = 1
1.45 + path_encoding = None
1.46 +
1.47 + def __init__(self, resource, authenticator, login_url=None, app_url=None):
1.48
1.49 """
1.50 Initialise the resource with a 'resource' for the application being
1.51 @@ -45,39 +75,12 @@
1.52
1.53 The 'app_url' should be the "bare" reference using a protocol, host
1.54 and port, not including any path information.
1.55 -
1.56 - If the optional 'anonymous_parameter_name' is set, clients providing a
1.57 - parameter of that name in the URL will not be authenticated, but then
1.58 - such clients will get a predefined user identity associated with them,
1.59 - configurable using the optional 'anonymous_username'.
1.60 -
1.61 - If the optional 'logout_parameter_name' is set, clients providing a
1.62 - parameter of that name in the URL will become logged out. After logging
1.63 - out, clients are redirected to a location which can be configured by the
1.64 - optional 'logout_url'.
1.65 -
1.66 - If the optional 'use_logout_redirect' flag is set to 0, a confirmation
1.67 - screen is given instead of redirecting the user to the 'logout_url'.
1.68 -
1.69 - The optional 'path_encoding' parameter (previously 'urlencoding', which
1.70 - is still supported) allows a special encoding to be used in producing
1.71 - the redirection path.
1.72 -
1.73 - To change the page used by this resource, either redefine the
1.74 - 'logout_page' attribute in instances of this class or a subclass, or
1.75 - override the 'show_logout' method.
1.76 """
1.77
1.78 self.login_url = login_url
1.79 self.app_url = app_url
1.80 self.resource = resource
1.81 self.authenticator = authenticator
1.82 - self.anonymous_parameter_name = anonymous_parameter_name
1.83 - self.anonymous_username = anonymous_username
1.84 - self.logout_parameter_name = logout_parameter_name
1.85 - self.logout_url = logout_url
1.86 - self.use_logout_redirect = use_logout_redirect
1.87 - self.path_encoding = path_encoding or urlencoding
1.88
1.89 def respond(self, trans):
1.90
1.91 @@ -179,6 +182,28 @@
1.92 </html>
1.93 """
1.94
1.95 +class SiteLoginRedirectResource(LoginRedirectResource):
1.96 +
1.97 + "Login redirection within a site."
1.98 +
1.99 + site_attribute_name = "root"
1.100 +
1.101 + def _get_url(self, trans, site_relative_url):
1.102 +
1.103 + "Return the URL, using 'trans', for the given 'site_relative_url'."
1.104 +
1.105 + return trans.get_attributes()[self.site_attribute_name] + site_relative_url
1.106 +
1.107 + def get_login_url(self, trans):
1.108 +
1.109 + """
1.110 + Return the login URL, using 'trans' if necessary, in order to
1.111 + provide a complete URL to redirect an authenticated user to their
1.112 + originally requested page.
1.113 + """
1.114 +
1.115 + return self._get_url(trans, LoginRedirectResource.get_login_url(self, trans))
1.116 +
1.117 class LoginRedirectAuthenticator(Verifier):
1.118
1.119 """