server/repository.py
branchstable
changeset 5032 e3fa27fc0d9a
parent 5030 5238d9a8dfee
child 5043 fe52dd3936cf
equal deleted inserted replaced
5031:60c4dea96afa 5032:e3fa27fc0d9a
   505                                    'P pkey K, P value V, NOT P for_user U',
   505                                    'P pkey K, P value V, NOT P for_user U',
   506                                    build_descr=False)
   506                                    build_descr=False)
   507         finally:
   507         finally:
   508             session.close()
   508             session.close()
   509 
   509 
       
   510     # XXX protect this method: anonymous should be allowed and registration
       
   511     # plugged
   510     def register_user(self, login, password, email=None, **kwargs):
   512     def register_user(self, login, password, email=None, **kwargs):
   511         """check a user with the given login exists, if not create it with the
   513         """check a user with the given login exists, if not create it with the
   512         given password. This method is designed to be used for anonymous
   514         given password. This method is designed to be used for anonymous
   513         registration on public web site.
   515         registration on public web site.
   514         """
   516         """
   515         # XXX should not be called from web interface
       
   516         session = self.internal_session()
   517         session = self.internal_session()
   517         # for consistency, keep same error as unique check hook (although not required)
   518         # for consistency, keep same error as unique check hook (although not required)
   518         errmsg = session._('the value "%s" is already used, use another one')
   519         errmsg = session._('the value "%s" is already used, use another one')
   519         try:
   520         try:
   520             if (session.execute('CWUser X WHERE X login %(login)s', {'login': login})
   521             if (session.execute('CWUser X WHERE X login %(login)s', {'login': login})
   537                 d = {'login': login, 'email': email or login}
   538                 d = {'login': login, 'email': email or login}
   538                 if session.execute('EmailAddress X WHERE X address %(email)s', d):
   539                 if session.execute('EmailAddress X WHERE X address %(email)s', d):
   539                     qname = role_name('address', 'subject')
   540                     qname = role_name('address', 'subject')
   540                     raise ValidationError(None, {qname: errmsg % d['email']})
   541                     raise ValidationError(None, {qname: errmsg % d['email']})
   541                 session.execute('INSERT EmailAddress X: X address %(email)s, '
   542                 session.execute('INSERT EmailAddress X: X address %(email)s, '
   542                                 'U primary_email X, U use_email X WHERE U login %(login)s', d)
   543                                 'U primary_email X, U use_email X '
       
   544                                 'WHERE U login %(login)s', d)
   543             session.commit()
   545             session.commit()
   544         finally:
   546         finally:
   545             session.close()
   547             session.close()
   546         return True
   548         return True
   547 
   549 
   611             return self.type_and_source_from_eid(eid, session)
   613             return self.type_and_source_from_eid(eid, session)
   612         finally:
   614         finally:
   613             session.reset_pool()
   615             session.reset_pool()
   614 
   616 
   615     def check_session(self, sessionid):
   617     def check_session(self, sessionid):
   616         """raise `BadSessionId` if the connection is no more valid"""
   618         """raise `BadConnectionId` if the connection is no more valid"""
   617         self._get_session(sessionid, setpool=False)
   619         self._get_session(sessionid, setpool=False)
   618 
   620 
   619     def get_shared_data(self, sessionid, key, default=None, pop=False):
   621     def get_shared_data(self, sessionid, key, default=None, pop=False):
   620         """return the session's data dictionary"""
   622         """return the session's data dictionary"""
   621         session = self._get_session(sessionid, setpool=False)
   623         session = self._get_session(sessionid, setpool=False)