Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Split /login into client_reader
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Feb 18, 2019
1 parent af691e4 commit 4cc4400
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 41 deletions.
2 changes: 2 additions & 0 deletions synapse/app/client_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from synapse.replication.slave.storage.room import RoomStore
from synapse.replication.slave.storage.transactions import SlavedTransactionStore
from synapse.replication.tcp.client import ReplicationClientHandler
from synapse.rest.client.v1.login import LoginRestServlet
from synapse.rest.client.v1.room import (
JoinedRoomMemberListRestServlet,
PublicRoomListRestServlet,
Expand Down Expand Up @@ -94,6 +95,7 @@ def _listen_http(self, listener_config):
RoomStateRestServlet(self).register(resource)
RoomEventContextServlet(self).register(resource)
RegisterRestServlet(self).register(resource)
LoginRestServlet(self).register(resource)

resources.update({
"/_matrix/client/r0": resource,
Expand Down
82 changes: 41 additions & 41 deletions synapse/storage/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,47 @@ def get_3pid_guest_access_token(self, medium, address):
defer.returnValue(ret["guest_access_token"])
defer.returnValue(None)

@defer.inlineCallbacks
def get_user_id_by_threepid(self, medium, address):
"""Returns user id from threepid
Args:
medium (str): threepid medium e.g. email
address (str): threepid address e.g. me@example.com
Returns:
Deferred[str|None]: user id or None if no user id/threepid mapping exists
"""
user_id = yield self.runInteraction(
"get_user_id_by_threepid", self.get_user_id_by_threepid_txn,
medium, address
)
defer.returnValue(user_id)

def get_user_id_by_threepid_txn(self, txn, medium, address):
"""Returns user id from threepid
Args:
txn (cursor):
medium (str): threepid medium e.g. email
address (str): threepid address e.g. me@example.com
Returns:
str|None: user id or None if no user id/threepid mapping exists
"""
ret = self._simple_select_one_txn(
txn,
"user_threepids",
{
"medium": medium,
"address": address
},
['user_id'], True
)
if ret:
return ret['user_id']
return None


class RegistrationStore(RegistrationWorkerStore,
background_updates.BackgroundUpdateStore):
Expand Down Expand Up @@ -613,47 +654,6 @@ def user_get_threepids(self, user_id):
)
defer.returnValue(ret)

@defer.inlineCallbacks
def get_user_id_by_threepid(self, medium, address):
"""Returns user id from threepid
Args:
medium (str): threepid medium e.g. email
address (str): threepid address e.g. me@example.com
Returns:
Deferred[str|None]: user id or None if no user id/threepid mapping exists
"""
user_id = yield self.runInteraction(
"get_user_id_by_threepid", self.get_user_id_by_threepid_txn,
medium, address
)
defer.returnValue(user_id)

def get_user_id_by_threepid_txn(self, txn, medium, address):
"""Returns user id from threepid
Args:
txn (cursor):
medium (str): threepid medium e.g. email
address (str): threepid address e.g. me@example.com
Returns:
str|None: user id or None if no user id/threepid mapping exists
"""
ret = self._simple_select_one_txn(
txn,
"user_threepids",
{
"medium": medium,
"address": address
},
['user_id'], True
)
if ret:
return ret['user_id']
return None

def user_delete_threepid(self, user_id, medium, address):
return self._simple_delete(
"user_threepids",
Expand Down

0 comments on commit 4cc4400

Please sign in to comment.