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.")
|