Changeset 180 for oss/oidtool

Show
Ignore:
Timestamp:
12/28/06 05:26:19 (2 years ago)
Author:
sylvain
Message:

Reverted to use cherrypy.session for now on (which takes care of concurrency)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • oss/oidtool/oidtool.py

    r178 r180  
    6565 
    6666class OpenIDTool: 
    67     def __init__(self, store, base_auth_path, session=None, session_name=DEFAULT_SESSION_NAME): 
     67    def __init__(self, store, base_auth_path, session_name=DEFAULT_SESSION_NAME): 
    6868        """ 
    6969        This tool provides a fairly easy way to add a OpenID consumer to your CherryPy 
     
    9393        really flexible. 
    9494         
    95         session -- an object that respects the dictionnary interface and which will hold 
    96         every session. When not provided it defaults to the cherrypy.session object. In that case 
    97         you must not forget to enable the session tool itself. 
    98          
    9995        session_name -- name to give to the session node within the session object (when using 
    10096        a cookie this is the cookie name for instance) 
    10197        """ 
    10298        self.store = store 
    103         self.session = session 
    10499        self.session_name = session_name 
    105100        self.base_auth_path = base_auth_path + '/' 
     
    110105         
    111106    def get_session(self): 
    112         oidsession = self.session.get(self.session_name, None) 
     107        oidsession = cherrypy.session.get(self.session_name, None) 
    113108         
    114109        if not oidsession or not isinstance(oidsession, dict): 
     
    118113            sid = randomString(16, '0123456789abcdef') 
    119114            oidsession['sid'] = sid 
    120             self.session[self.session_name] = oidsession 
    121             self.session[self.session_name]['status'] = UNKNOWN 
    122          
    123         return self.session[self.session_name] 
     115            cherrypy.session[self.session_name] = oidsession 
     116            cherrypy.session[self.session_name]['status'] = UNKNOWN 
     117         
     118        return cherrypy.session[self.session_name] 
    124119 
    125120    def is_processing(self): 
    126         if self.session.has_key(self.session_name): 
    127             if 'status' in self.session[self.session_name]: 
    128                 if self.session[self.session_name]['status'] in [PROCESSING, AUTHENTICATED]: 
     121        if cherrypy.session.has_key(self.session_name): 
     122            if 'status' in cherrypy.session[self.session_name]: 
     123                if cherrypy.session[self.session_name]['status'] in [PROCESSING, AUTHENTICATED]: 
    129124                    return True 
    130125        return False 
    131126 
    132127    def is_authenticated(self): 
    133         if self.session.has_key(self.session_name): 
    134             if 'status' in self.session[self.session_name]: 
    135                 if self.session[self.session_name]['status'] == AUTHENTICATED: 
     128        if cherrypy.session.has_key(self.session_name): 
     129            if 'status' in cherrypy.session[self.session_name]: 
     130                if cherrypy.session[self.session_name]['status'] == AUTHENTICATED: 
    136131                    return True 
    137132        return False 
     
    148143            return 
    149144         
    150         if not self.session: 
    151             self.session = cherrypy.session 
    152  
    153145        # this method is always called so we check if we haven't already 
    154146        # been authenticated or if we are not in the middle of 
     
    183175                redirect_url = request.redirectURL(cherrypy.request.base, return_to) 
    184176 
    185                 self.session[self.session_name]['status'] = PROCESSING 
     177                cherrypy.session[self.session_name]['status'] = PROCESSING 
    186178                raise cherrypy.HTTPRedirect(redirect_url) 
    187179 
     
    197189            return 
    198190         
    199         if not self.session: 
    200             self.session = cherrypy.session 
    201              
    202191        # If we are already authenticated then we don't apply this step 
    203192        # any further 
     
    207196        oidconsumer = consumer.Consumer(self.get_session(), self.store) 
    208197 
    209         self.session[self.session_name]['status'] = UNKNOWN 
     198        cherrypy.session[self.session_name]['status'] = UNKNOWN 
    210199         
    211200        # Ask the library to check the response that the server sent 
     
    214203        # the return type. 
    215204        info = oidconsumer.complete(cherrypy.request.params) 
    216         self.session[self.session_name]['info'] = info 
     205        cherrypy.session[self.session_name]['info'] = info 
    217206        if info.status == consumer.FAILURE and info.identity_url: 
    218207            # In the case of failure, if info is non-None, it is the 
     
    234223                # i-name registration expires and is bought by someone else. 
    235224                pass 
    236             self.session[self.session_name]['status'] = AUTHENTICATED 
     225            cherrypy.session[self.session_name]['status'] = AUTHENTICATED 
    237226            cherrypy.request.params = {} 
    238227            raise cherrypy.HTTPRedirect(cherrypy.url(cherrypy.request.path_info))