#NEWLINE# @ defer . inlineCallbacks #NEWLINE# def check_auth( self , flows , clientdict , clientip ) : #NEWLINE# #INDENT# "\n        Takes a dictionary sent by the client in the login / registration\n        protocol and handles the login flow.\n\n        As a side effect, this function fills in the 'creds' key on the user's\n        session with a map, which maps each auth-type (str) to the relevant\n        identity authenticated by that auth-type (mostly str, but for captcha, bool).\n\n        Args:\n            flows (list): A list of login flows. Each flow is an ordered list of\n                          strings representing auth-types. At least one full\n                          flow must be completed in order for auth to be successful.\n            clientdict: The dictionary from the client root level, not the\n                        'auth' key: this method prompts for auth if none is sent.\n            clientip (str): The IP address of the client.\n        Returns:\n            A tuple of (authed, dict, dict, session_id) where authed is true if\n            the client has successfully completed an auth flow. If it is true\n            the first dict contains the authenticated credentials of each stage.\n\n            If authed is false, the first dictionary is the server response to\n            the login request and should be passed back to the client.\n\n            In either case, the second dict contains the parameters for this\n            request (which may have been given only in a previous call).\n\n            session_id is the ID of this session, either passed in by the client\n            or assigned by the call to check_auth\n        " #NEWLINE# authdict = None #NEWLINE# sid = None #NEWLINE# if ( clientdict and ( 'auth' in clientdict ) ) : #NEWLINE# #INDENT# authdict = clientdict [ 'auth' ] #NEWLINE# del clientdict [ 'auth' ] #NEWLINE# if ( 'session' in authdict ) : #NEWLINE# #INDENT# sid = authdict [ 'session' ] #NEWLINE# #UNINDENT# #UNINDENT# session = self . _get_session_info ( sid ) #NEWLINE# if ( len ( f ) > 0 ) : #NEWLINE# #INDENT# session [ 'clientdict' ] = clientdict #NEWLINE# self . _save_session ( session ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'clientdict' in session ) : #NEWLINE# #INDENT# clientdict = session [ 'clientdict' ] #NEWLINE# #UNINDENT# #UNINDENT# if ( not authdict ) : #NEWLINE# #INDENT# defer . returnValue ( ( False , self . _auth_dict_for_flows ( flows , session ) , clientdict , session [ 'id' ] ) ) #NEWLINE# #UNINDENT# if ( 'creds' not in session ) : #NEWLINE# #INDENT# session [ 'creds' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# creds = session [ 'creds' ] #NEWLINE# if ( 'type' in authdict ) : #NEWLINE# #INDENT# if ( authdict [ 'type' ] not in self . checkers ) : #NEWLINE# #INDENT# raise LoginError ( 400 , '' , Codes . UNRECOGNIZED ) #NEWLINE# #UNINDENT# result = ( yield self . checkers [ authdict [ 'type' ] ] ( authdict , clientip ) ) #NEWLINE# if result : #NEWLINE# #INDENT# creds [ authdict [ 'type' ] ] = result #NEWLINE# self . _save_session ( session ) #NEWLINE# #UNINDENT# #UNINDENT# for f in flows : #NEWLINE# #INDENT# if ( len ( ( set ( f ) - set ( creds . keys ( ) ) ) ) == 0 ) : #NEWLINE# #INDENT# logger . info ( 'Auth completed with creds: %r' , creds ) #NEWLINE# defer . returnValue ( ( True , creds , clientdict , session [ 'id' ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# ret = self . _auth_dict_for_flows ( flows , session ) #NEWLINE# ret [ 'completed' ] = creds . keys ( ) #NEWLINE# defer . returnValue ( ( False , ret , clientdict , session [ 'id' ] ) )