Source code for uw.local.util.identity

from uw.web.wsgi.parameter import get_params, ParamHandler

[docs]def set_remote_identity (handler): """Wrap a handler; store identity associated with $REMOTE_USER. Returns a handler which saves the identity associated with the remote user in the environment before chaining to the provided handler. Requires access to the database through the already-defined "cursor" parameter. """ def result (environ, start_response): environ['remote_identity'] = (get_params (environ)['cursor']).execute_optional_tuple ("select * from person_identity_complete where userid=%(userid)s", userid=environ.get ('REMOTE_USER')) return handler (environ, start_response) return result
[docs]def use_remote_identity (handler): """Wrap a handler; access identity associated with $REMOTE_USER. Returns a handler which copy the identity associated with the remote user from the environment to the 'remote_identity' parameter before chaining to the provided handler. Resulting handler must eventually be wrapped by set_remote_identity. """ return ParamHandler (handler, 'remote_identity', lambda environ: environ.get ('remote_identity'))