changeset 8:c958eb9300da

add bitsy factory for filter
author egj@socialplanning.org
date Mon, 04 Jan 2010 01:46:25 +0000
parents 672a4dd85763
children 73b2b5bccd52
files bitsyauth/__init__.py bitsyauth/factory.py
diffstat 2 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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'):
--- /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