summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2019-09-09 17:03:31 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2019-09-09 17:03:31 +0100
commitccbd9dc5ac1b15da55f996799a41a5316e8c2999 (patch)
tree56705c04a984b61f25bd3a2915df146bc4c2d886
parentlint (diff)
downloadsynapse-github/anoa/msc2229.tar.xz
-rw-r--r--synapse/rest/client/v2_alpha/account.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/synapse/rest/client/v2_alpha/account.py b/synapse/rest/client/v2_alpha/account.py
index f19321d794..fb2179651e 100644
--- a/synapse/rest/client/v2_alpha/account.py
+++ b/synapse/rest/client/v2_alpha/account.py
@@ -456,10 +456,12 @@ class EmailThreepidRequestTokenRestServlet(RestServlet):
         # If the request is authenticated, allow this MSISDN to be rebound if the requester
         # owns it.
         # Otherwise, deny the request if the 3PID exists
-        if (requester and existing_user_id != requester.user.to_string()) or (
-            requester is None and existing_user_id
-        ):
-            raise SynapseError(400, "Email is already in use", Codes.THREEPID_IN_USE)
+        if existing_user_id:
+            if (
+                requester is None or
+                (requester and existing_user_id != requester.user.to_string)
+            ):
+                raise SynapseError(400, "Email is already in use", Codes.THREEPID_IN_USE)
 
         ret = yield self.identity_handler.requestEmailToken(
             id_server, email, client_secret, send_attempt, next_link
@@ -512,10 +514,12 @@ class MsisdnThreepidRequestTokenRestServlet(RestServlet):
         # If the request is authenticated, allow this MSISDN to be rebound if the requester
         # owns it.
         # Otherwise, deny the request if the 3PID exists
-        if (requester and existing_user_id != requester.user.to_string()) or (
-            requester is None and existing_user_id
-        ):
-            raise SynapseError(400, "MSISDN is already in use", Codes.THREEPID_IN_USE)
+        if existing_user_id:
+            if (
+                requester is None or
+                (requester and existing_user_id != requester.user.to_string)
+            ):
+                raise SynapseError(400, "MSISDN is already in use", Codes.THREEPID_IN_USE)
 
         ret = yield self.identity_handler.requestMsisdnToken(
             id_server, country, phone_number, client_secret, send_attempt, next_link
@@ -570,9 +574,10 @@ class ThreepidRestServlet(RestServlet):
 
         # Check that the user is not trying to add an email that's already bound to another
         # user
-        if existing_user_id != requester.user.to_string():
+        if existing_user_id and existing_user_id != requester.user.to_string():
             raise SynapseError(
-                400, "This 3PID is already in use", Codes.THREEPID_IN_USE
+                400, "This 3PID is already in use by %s" % (existing_user_id,),
+                Codes.THREEPID_IN_USE,
             )
 
         yield self.auth_handler.add_threepid(