31 from cubicweb import (CW_SOFTWARE_ROOT, UnknownEid, AuthenticationError, |
31 from cubicweb import (CW_SOFTWARE_ROOT, UnknownEid, AuthenticationError, |
32 ETypeNotSupportedBySources, RTypeNotSupportedBySources, |
32 ETypeNotSupportedBySources, RTypeNotSupportedBySources, |
33 BadConnectionId, Unauthorized, ValidationError, |
33 BadConnectionId, Unauthorized, ValidationError, |
34 ExecutionError, typed_eid, |
34 ExecutionError, typed_eid, |
35 CW_MIGRATION_MAP) |
35 CW_MIGRATION_MAP) |
36 from cubicweb.cwvreg import CubicWebRegistry |
36 from cubicweb.cwvreg import CubicWebVRegistry |
37 from cubicweb.schema import VIRTUAL_RTYPES, CubicWebSchema |
37 from cubicweb.schema import VIRTUAL_RTYPES, CubicWebSchema |
38 from cubicweb import server |
38 from cubicweb import server |
39 from cubicweb.server.utils import RepoThread, LoopTask |
39 from cubicweb.server.utils import RepoThread, LoopTask |
40 from cubicweb.server.pool import ConnectionsPool, LateOperation, SingleLastOperation |
40 from cubicweb.server.pool import ConnectionsPool, LateOperation, SingleLastOperation |
41 from cubicweb.server.session import Session, InternalSession |
41 from cubicweb.server.session import Session, InternalSession |
135 """ |
135 """ |
136 |
136 |
137 def __init__(self, config, vreg=None, debug=False): |
137 def __init__(self, config, vreg=None, debug=False): |
138 self.config = config |
138 self.config = config |
139 if vreg is None: |
139 if vreg is None: |
140 vreg = CubicWebRegistry(config, debug) |
140 vreg = CubicWebVRegistry(config, debug) |
141 self.vreg = vreg |
141 self.vreg = vreg |
142 self.pyro_registered = False |
142 self.pyro_registered = False |
143 self.info('starting repository from %s', self.config.apphome) |
143 self.info('starting repository from %s', self.config.apphome) |
144 # dictionary of opened sessions |
144 # dictionary of opened sessions |
145 self._sessions = {} |
145 self._sessions = {} |
426 raise AuthenticationError('user is not in authenticable state') |
426 raise AuthenticationError('user is not in authenticable state') |
427 return cwuser |
427 return cwuser |
428 |
428 |
429 def _build_user(self, session, eid): |
429 def _build_user(self, session, eid): |
430 """return a CWUser entity for user with the given eid""" |
430 """return a CWUser entity for user with the given eid""" |
431 cls = self.vreg.etype_class('CWUser') |
431 cls = self.vreg['etypes'].etype_class('CWUser') |
432 rql = cls.fetch_rql(session.user, ['X eid %(x)s']) |
432 rql = cls.fetch_rql(session.user, ['X eid %(x)s']) |
433 rset = session.execute(rql, {'x': eid}, 'x') |
433 rset = session.execute(rql, {'x': eid}, 'x') |
434 assert len(rset) == 1, rset |
434 assert len(rset) == 1, rset |
435 cwuser = rset.get_entity(0, 0) |
435 cwuser = rset.get_entity(0, 0) |
436 # pylint: disable-msg=W0104 |
436 # pylint: disable-msg=W0104 |
530 if (session.execute('CWUser X WHERE X login %(login)s', {'login': login}) |
530 if (session.execute('CWUser X WHERE X login %(login)s', {'login': login}) |
531 or session.execute('CWUser X WHERE X use_email C, C address %(login)s', |
531 or session.execute('CWUser X WHERE X use_email C, C address %(login)s', |
532 {'login': login})): |
532 {'login': login})): |
533 raise ValidationError(None, {'login': errmsg % login}) |
533 raise ValidationError(None, {'login': errmsg % login}) |
534 # we have to create the user |
534 # we have to create the user |
535 user = self.vreg.etype_class('CWUser')(session, None) |
535 user = self.vreg['etypes'].etype_class('CWUser')(session, None) |
536 if isinstance(password, unicode): |
536 if isinstance(password, unicode): |
537 # password should *always* be utf8 encoded |
537 # password should *always* be utf8 encoded |
538 password = password.encode('UTF8') |
538 password = password.encode('UTF8') |
539 kwargs['login'] = login |
539 kwargs['login'] = login |
540 kwargs['upassword'] = password |
540 kwargs['upassword'] = password |