Changeset 107

Show
Ignore:
Timestamp:
08/09/07 13:08:54
Author:
thejimmyg
Message:

Changed form middleware so you can choose which status it returns and so that it tells the Pylons error docuement middleware not to intercept a 401 response it generates

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • AuthKit/branches/0.4/authkit/authenticate/form.py

    r71 r107  
    44detail in the AuthKit manual and should be used via the 
    55``authkit.authenticate.middleware`` function. 
     6 
     7The option form.status can be set to "200 OK" if the Pylons error document 
     8middleware is intercepting the 401 response and just showing the standard 401 
     9error document. This will not happen in recent versions of Pylons (0.9.6) 
     10because this middleware sets the environ['pylons.error_call'] key so that the 
     11error documents middleware doesn't intercept the response. 
    612""" 
    713 
     
    1117   get_authenticate_function, strip_base, RequireEnvironKey 
    1218from authkit.authenticate.multi import MultiHandler, status_checker 
     19 
     20import logging 
     21log = logging.getLogger('authkit.authenticate.form') 
    1322 
    1423def template(): 
     
    3645        app, 
    3746        charset=None, 
     47        status="401 Unauthorized", 
    3848        **p 
    3949    ): 
    4050        AuthFormHandler.__init__(self, app, **p) 
     51        self.status = status 
    4152        if charset is None: 
    4253            self.charset = '' 
     
    6576                    del environ['paste.parsed_formvars'] 
    6677                    return self.on_authorized(environ, start_response) 
    67  
    68         content = self.template() % construct_url(environ) 
    69         start_response("401 Unauthorized",[('Content-Type', 'text/html'+self.charset), 
     78        action =  construct_url(environ) 
     79        log.debug("Form action is: %s", action) 
     80        content = self.template() % action 
     81        # @@@ Tell Pylons error documents middleware not to intercept the  
     82        # response 
     83        environ['pylons.error_call'] = 'authkit' 
     84        start_response(self.status,[('Content-Type', 'text/html'+self.charset), 
    7085                                 ('Content-Length', str(len(content)))]) 
    7186        return [content] 
  • AuthKit/branches/0.4/authkit/authenticate/multi.py

    r86 r107  
    5353                if checker(environ, status_[0], headers_ and headers_[0] or []): 
    5454                    log.debug( 
    55                         "MultMiddleware self.checker check() returning %r",  
     55                        "MultiMiddleware self.checker check() returning %r",  
    5656                        binding 
    5757                    )