merge tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 15 Apr 2009 17:30:03 +0200
branchtls-sprint
changeset 1373 5e6abf61636d
parent 1370 c1cf86a66e30 (current diff)
parent 1372 d4264cd876e1 (diff)
child 1380 aa1586de4563
merge
--- a/server/repository.py	Wed Apr 15 17:25:20 2009 +0200
+++ b/server/repository.py	Wed Apr 15 17:30:03 2009 +0200
@@ -490,18 +490,19 @@
         finally:
             session.close()
 
-    def register_user(self, login, password, **kwargs):
+    def register_user(self, login, password, email=None, **kwargs):
         """check a user with the given login exists, if not create it with the
         given password. This method is designed to be used for anonymous
         registration on public web site.
         """
         session = self.internal_session()
+        # for consistency, keep same error as unique check hook (although not required)
+        errmsg = session._('the value "%s" is already used, use another one')
         try:
-            if session.execute('EUser X WHERE X login %(login)s', {'login': login}):
-                return False
-            if session.execute('EUser X WHERE X use_email C, C address %(login)s',
-                               {'login': login}):
-                return False
+            if (session.execute('EUser X WHERE X login %(login)s', {'login': login})
+                or session.execute('EUser X WHERE X use_email C, C address %(login)s',
+                                   {'login': login})):
+                raise ValidationError(None, {'login': errmsg % login})
             # we have to create the user
             user = self.vreg.etype_class('EUser')(session, None)
             if isinstance(password, unicode):
@@ -513,11 +514,12 @@
             self.glob_add_entity(session, user)
             session.execute('SET X in_group G WHERE X eid %(x)s, G name "users"',
                             {'x': user.eid})
-            # FIXME this does not work yet
-            if '@' in login:
-                session.execute('INSERT EmailAddress X: X address "%(login)s", '
-                                'U primary_email X, U use_email X WHERE U login "%(login)s"',
-                                {'login':login})
+            if email or '@' in login:
+                d = {'login': login, 'email': email or login}
+                if session.execute('EmailAddress X WHERE X address %(email)s', d):
+                    raise ValidationError(None, {'address': errmsg % d['email']})
+                session.execute('INSERT EmailAddress X: X address %(email)s, '
+                                'U primary_email X, U use_email X WHERE U login %(login)s', d)
             session.commit()
         finally:
             session.close()