summary refs log tree commit diff
path: root/synapse/storage/registration.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-09-29 14:59:52 +0100
committerErik Johnston <erik@matrix.org>2014-09-29 14:59:52 +0100
commit3ccb17ce592d7e75e0bd0237c347d64f63d5eb10 (patch)
treec5931cd53ad04a32430a51afcb8b7a06ea88920d /synapse/storage/registration.py
parentAdd auth check to test if a user is an admin or not. (diff)
downloadsynapse-3ccb17ce592d7e75e0bd0237c347d64f63d5eb10.tar.xz
SYN-48: Implement WHOIS rest servlet
Diffstat (limited to 'synapse/storage/registration.py')
-rw-r--r--synapse/storage/registration.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/synapse/storage/registration.py b/synapse/storage/registration.py
index f32b000cb6..cf43209367 100644
--- a/synapse/storage/registration.py
+++ b/synapse/storage/registration.py
@@ -88,7 +88,6 @@ class RegistrationStore(SQLBaseStore):
             query, user_id
         )
 
-    @defer.inlineCallbacks
     def get_user_by_token(self, token):
         """Get a user from the given access token.
 
@@ -99,11 +98,11 @@ class RegistrationStore(SQLBaseStore):
         Raises:
             StoreError if no user was found.
         """
-        user_id = yield self.runInteraction(self._query_for_auth,
-                                                     token)
-        defer.returnValue(user_id)
+        return self.runInteraction(
+            self._query_for_auth,
+            token
+        )
 
-    @defer.inlineCallbacks
     def is_server_admin(self, user):
         return self._simple_select_one_onecol(
             table="users",
@@ -112,11 +111,16 @@ class RegistrationStore(SQLBaseStore):
         )
 
     def _query_for_auth(self, txn, token):
-        txn.execute("SELECT users.name FROM access_tokens LEFT JOIN users" +
-                    " ON users.id = access_tokens.user_id WHERE token = ?",
-                    [token])
-        row = txn.fetchone()
-        if row:
-            return row[0]
+        sql = (
+            "SELECT users.name, users.admin, access_tokens.device_id "
+            "FROM users "
+            "INNER JOIN access_tokens on users.id = access_tokens.user_id "
+            "WHERE token = ?"
+        )
+
+        cursor = txn.execute(sql, (token,))
+        rows = self.cursor_to_dict(cursor)
+        if rows:
+            return rows[0]
 
         raise StoreError(404, "Token not found.")