summary refs log tree commit diff
path: root/synapse/rest/client/v2_alpha/register.py
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-04-17 16:44:49 +0100
committerDavid Baker <dave@matrix.org>2015-04-17 16:44:49 +0100
commitf96ab9d18dcebf995700f096792101a490b3a9b8 (patch)
tree56f0a7ec4737b381312ed181fbd41578cd3e002f /synapse/rest/client/v2_alpha/register.py
parentjust the once would probably be fine (diff)
downloadsynapse-f96ab9d18dcebf995700f096792101a490b3a9b8.tar.xz
make add3pid servlet work
Diffstat (limited to 'synapse/rest/client/v2_alpha/register.py')
-rw-r--r--synapse/rest/client/v2_alpha/register.py38
1 files changed, 26 insertions, 12 deletions
diff --git a/synapse/rest/client/v2_alpha/register.py b/synapse/rest/client/v2_alpha/register.py
index a5fec45dce..e93897e285 100644
--- a/synapse/rest/client/v2_alpha/register.py
+++ b/synapse/rest/client/v2_alpha/register.py
@@ -50,6 +50,7 @@ class RegisterRestServlet(RestServlet):
         self.auth_handler = hs.get_handlers().auth_handler
         self.registration_handler = hs.get_handlers().registration_handler
         self.identity_handler = hs.get_handlers().identity_handler
+        self.login_handler = hs.get_handlers().login_handler
 
     @defer.inlineCallbacks
     def on_POST(self, request):
@@ -61,7 +62,6 @@ class RegisterRestServlet(RestServlet):
 
         if 'username' in body:
             desired_username = body['username']
-            print "username in body"
             yield self.registration_handler.check_username(desired_username)
 
         is_using_shared_secret = False
@@ -118,17 +118,31 @@ class RegisterRestServlet(RestServlet):
             password=new_password
         )
 
-        if 'bind_email' in params and params['bind_email']:
-            logger.info("bind_email specified: binding")
-
-            emailThreepid = result[LoginType.EMAIL_IDENTITY]
-            threepidCreds = emailThreepid['threepidCreds']
-            logger.debug("Binding emails %s to %s" % (
-                emailThreepid, user_id
-            ))
-            yield self.identity_handler.bind_threepid(threepidCreds, user_id)
-        else:
-            logger.info("bind_email not specified: not binding email")
+        if LoginType.EMAIL_IDENTITY in result:
+            threepid = result[LoginType.EMAIL_IDENTITY]
+
+            for reqd in ['medium', 'address', 'validatedAt']:
+                if reqd not in threepid:
+                    logger.info("Can't add incomplete 3pid")
+                else:
+                    yield self.login_handler.add_threepid(
+                        user_id,
+                        threepid['medium'],
+                        threepid['address'],
+                        threepid['validatedAt'],
+                    )
+
+            if 'bind_email' in params and params['bind_email']:
+                logger.info("bind_email specified: binding")
+
+                emailThreepid = result[LoginType.EMAIL_IDENTITY]
+                threepidCreds = emailThreepid['threepidCreds']
+                logger.debug("Binding emails %s to %s" % (
+                    emailThreepid, user_id
+                ))
+                yield self.identity_handler.bind_threepid(threepidCreds, user_id)
+            else:
+                logger.info("bind_email not specified: not binding email")
 
         result = {
             "user_id": user_id,