server/sources/native.py
changeset 6849 5a0c2cfc19bf
parent 6724 24bf6f181d0e
child 6851 824d5b6eae7f
equal deleted inserted replaced
6848:f87cd875c6db 6849:5a0c2cfc19bf
   264     )
   264     )
   265 
   265 
   266     def __init__(self, repo, source_config, *args, **kwargs):
   266     def __init__(self, repo, source_config, *args, **kwargs):
   267         SQLAdapterMixIn.__init__(self, source_config)
   267         SQLAdapterMixIn.__init__(self, source_config)
   268         self.authentifiers = [LoginPasswordAuthentifier(self)]
   268         self.authentifiers = [LoginPasswordAuthentifier(self)]
       
   269         if repo.config['allow-email-login']:
       
   270             self.authentifiers.insert(0, EmailPasswordAuthentifier(self))
   269         AbstractSource.__init__(self, repo, source_config, *args, **kwargs)
   271         AbstractSource.__init__(self, repo, source_config, *args, **kwargs)
   270         # sql generator
   272         # sql generator
   271         self._rql_sqlgen = self.sqlgen_class(self.schema, self.dbhelper,
   273         self._rql_sqlgen = self.sqlgen_class(self.schema, self.dbhelper,
   272                                              ATTR_MAP.copy())
   274                                              ATTR_MAP.copy())
   273         # full text index helper
   275         # full text index helper
  1493         rset = self.source.syntax_tree_search(session, self._auth_rqlst, args)
  1495         rset = self.source.syntax_tree_search(session, self._auth_rqlst, args)
  1494         try:
  1496         try:
  1495             return rset[0][0]
  1497             return rset[0][0]
  1496         except IndexError:
  1498         except IndexError:
  1497             raise AuthenticationError('bad password')
  1499             raise AuthenticationError('bad password')
       
  1500 
       
  1501 
       
  1502 class EmailPasswordAuthentifier(BaseAuthentifier):
       
  1503     def authenticate(self, session, login, **authinfo):
       
  1504         # email_auth flag prevent from infinite recursion (call to
       
  1505         # repo.check_auth_info at the end of this method may lead us here again)
       
  1506         if not '@' in login or authinfo.pop('email_auth', None):
       
  1507             raise AuthenticationError('not an email')
       
  1508         rset = session.execute('Any L WHERE U login L, U primary_email M, '
       
  1509                                'M address %(login)s', {'login': login},
       
  1510                                build_descr=False)
       
  1511         if rset.rowcount != 1:
       
  1512             raise AuthenticationError('unexisting email')
       
  1513         login = rset.rows[0][0]
       
  1514         authinfo['email_auth'] = True
       
  1515         return self.source.repo.check_auth_info(session, login, authinfo)