summary refs log tree commit diff
path: root/synapse/handlers/register.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-03-13 12:04:38 +0000
committerErik Johnston <erik@matrix.org>2018-03-13 12:08:58 +0000
commit8b3573a8b209c60b03d5ef7f4dfed9ccb9e9f7b3 (patch)
tree13c6ef6efc9b2218a123fadc79ccec968789ca3b /synapse/handlers/register.py
parentMerge pull request #2962 from matrix-org/rav/purge_history_txns (diff)
downloadsynapse-8b3573a8b209c60b03d5ef7f4dfed9ccb9e9f7b3.tar.xz
Refactor get_or_register_3pid_guest
Diffstat (limited to 'synapse/handlers/register.py')
-rw-r--r--synapse/handlers/register.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py
index 9021d4d57f..ed5939880a 100644
--- a/synapse/handlers/register.py
+++ b/synapse/handlers/register.py
@@ -446,16 +446,34 @@ class RegistrationHandler(BaseHandler):
         return self.hs.get_auth_handler()
 
     @defer.inlineCallbacks
-    def guest_access_token_for(self, medium, address, inviter_user_id):
+    def get_or_register_3pid_guest(self, medium, address, inviter_user_id):
+        """Get a guest access token for a 3PID, creating a guest account if
+        one doesn't already exist.
+
+        Args:
+            medium (str)
+            address (str)
+            inviter_user_id (str): The user ID who is trying to invite the
+                3PID
+
+        Returns:
+            Deferred[(str, str)]: A 2-tuple of `(user_id, access_token)` of the
+            3PID guest account.
+        """
         access_token = yield self.store.get_3pid_guest_access_token(medium, address)
         if access_token:
-            defer.returnValue(access_token)
+            user_info = yield self.auth.get_user_by_access_token(
+                access_token
+            )
 
-        _, access_token = yield self.register(
+            defer.returnValue((user_info["user"].to_string(), access_token))
+
+        user_id, access_token = yield self.register(
             generate_token=True,
             make_guest=True
         )
         access_token = yield self.store.save_or_get_3pid_guest_access_token(
             medium, address, access_token, inviter_user_id
         )
-        defer.returnValue(access_token)
+
+        defer.returnValue((user_id, access_token))