#NEWLINE# def create_session( self , user_id = None , password = None , verify_password = True , key = None ) : #NEWLINE# #INDENT# 'Create a new session for the account with the given ``user_id`` and ``password``, or an anonymous\n      session if anonymous sessions are enabled. This method returns a subclass of ``TotoSession``\n      designed for the current backing database. Pass ``verify_password=False`` to create a session\n      without checking the password. This feature can be used to implement alternative authentication\n      methods like Facebook, Twitter or Google+.\n    ' #NEWLINE# if ( not user_id ) : #NEWLINE# #INDENT# user_id = '' #NEWLINE# #UNINDENT# user_id = user_id . lower ( ) #NEWLINE# account = ( user_id and self . _get_account ( user_id ) ) #NEWLINE# if ( user_id and ( ( not account ) or ( verify_password and ( not secret . verify_password ( password , account [ 'password' ] ) ) ) ) ) : #NEWLINE# #INDENT# raise TotoException ( ERROR_USER_NOT_FOUND , 'Invalid user ID or password' ) #NEWLINE# #UNINDENT# session_id = TotoSession . generate_id ( ) #NEWLINE# expires = ( time ( ) + ( ( user_id and self . session_ttl ) or self . anon_session_ttl ) ) #NEWLINE# session_data = { #NEWLINE# #INDENT# 'user_id' : user_id , #NEWLINE# 'expires' : expires , #NEWLINE# 'session_id' : session_id , #NEWLINE# #UNINDENT# } #NEWLINE# if session_data : #NEWLINE# #INDENT# session_data [ 'key' ] = key #NEWLINE# #UNINDENT# self . _prepare_session ( account , session_data ) #NEWLINE# if ( not self . _cache_session_data ( session_data ) ) : #NEWLINE# #INDENT# self . _store_session ( session_id , session_data ) #NEWLINE# #UNINDENT# session = self . _instantiate_session ( session_data , self . _session_cache ) #NEWLINE# return session