server/repository.py
changeset 3647 2941f4a0aab9
parent 3629 559cad62c786
child 3720 5376aaadd16b
equal deleted inserted replaced
3646:3bba270202ef 3647:2941f4a0aab9
   376                 login = rset[0][0]
   376                 login = rset[0][0]
   377         finally:
   377         finally:
   378             session.close()
   378             session.close()
   379         return login
   379         return login
   380 
   380 
   381     def authenticate_user(self, session, login, password):
   381     def authenticate_user(self, session, login, **kwargs):
   382         """validate login / password, raise AuthenticationError on failure
   382         """validate login / password, raise AuthenticationError on failure
   383         return associated CWUser instance on success
   383         return associated CWUser instance on success
   384         """
   384         """
   385         if self.vreg.config['allow-email-login'] and '@' in login:
   385         if self.vreg.config['allow-email-login'] and '@' in login:
   386             login = self._login_from_email(login)
   386             login = self._login_from_email(login)
   387         for source in self.sources:
   387         for source in self.sources:
   388             if source.support_entity('CWUser'):
   388             if source.support_entity('CWUser'):
   389                 try:
   389                 try:
   390                     eid = source.authenticate(session, login, password)
   390                     eid = source.authenticate(session, login, **kwargs)
   391                     break
   391                     break
   392                 except AuthenticationError:
   392                 except AuthenticationError:
   393                     continue
   393                     continue
   394         else:
   394         else:
   395             raise AuthenticationError('authentication failed with all sources')
   395             raise AuthenticationError('authentication failed with all sources')
   524             session.commit()
   524             session.commit()
   525         finally:
   525         finally:
   526             session.close()
   526             session.close()
   527         return True
   527         return True
   528 
   528 
   529     def connect(self, login, password, cnxprops=None):
   529     def connect(self, login, **kwargs):
   530         """open a connection for a given user
   530         """open a connection for a given user
   531 
   531 
   532         base_url may be needed to send mails
   532         base_url may be needed to send mails
   533         cnxtype indicate if this is a pyro connection or a in-memory connection
   533         cnxtype indicate if this is a pyro connection or a in-memory connection
   534 
   534 
   537         """
   537         """
   538         # use an internal connection
   538         # use an internal connection
   539         session = self.internal_session()
   539         session = self.internal_session()
   540         # try to get a user object
   540         # try to get a user object
   541         try:
   541         try:
   542             user = self.authenticate_user(session, login, password)
   542             user = self.authenticate_user(session, login, **kwargs)
   543         finally:
   543         finally:
   544             session.close()
   544             session.close()
   545         session = Session(user, self, cnxprops)
   545         session = Session(user, self, kwargs.get('cnxprops'))
   546         user._cw = user.cw_rset.req = session
   546         user._cw = user.cw_rset.req = session
   547         user.clear_related_cache()
   547         user.clear_related_cache()
   548         self._sessions[session.id] = session
   548         self._sessions[session.id] = session
   549         self.info('opened %s', session)
   549         self.info('opened %s', session)
   550         self.hm.call_hooks('session_open', session)
   550         self.hm.call_hooks('session_open', session)