# HG changeset patch # User egj@socialplanning.org # Date 1262569585 0 # Node ID c958eb9300da2f36653b4bb8047ea81c0560584c # Parent 672a4dd85763a2729c85bc46dd06c3891aea25af add bitsy factory for filter diff -r 672a4dd85763 -r c958eb9300da bitsyauth/__init__.py --- a/bitsyauth/__init__.py Sun Dec 27 01:24:02 2009 -0500 +++ b/bitsyauth/__init__.py Mon Jan 04 01:46:25 2010 +0000 @@ -67,9 +67,12 @@ def __call__(self, environ, start_response): + orig_environ = dict(environ) + self.request = Request(environ) self.request.path_info = self.request.path_info.rstrip('/') - self.redirect_to = self.request.script_name + + self.redirect_to = '/' + self.request.script_name.lstrip('/') # URLs intrinsic to BitsyAuth if self.request.path_info == '/logout': @@ -84,7 +87,8 @@ if self.request.headers.has_key('Authorization'): return self.wrapped_app(self.request.environ, start_response) - response = self.request.get_response(self.app) + response = Request(orig_environ).get_response(self.app) + # respond to 401s if response.status_int == 401: # Unauthorized if self.request.environ.get('REMOTE_USER'): diff -r 672a4dd85763 -r c958eb9300da bitsyauth/factory.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bitsyauth/factory.py Mon Jan 04 01:46:25 2010 +0000 @@ -0,0 +1,26 @@ +from bitsyauth import BitsyAuth +from paste.auth import digest + +def passworder_factory(username, password): + def passwords(): + return {username: password} + return passwords + +def filter_factory(global_conf, **app_conf): + + user = app_conf['user'] + site = app_conf.get('site', 'bitsyauth') + secret = app_conf.get('secret', 'secret') + password = app_conf['password'] + password = digest.digest_password(site, user, password) + passwords = passworder_factory(user, password) + + def filter(app): + return BitsyAuth( + app, + global_conf, + passwords, + newuser=None, + site=site, + secret=secret) + return filter