diff options
author | David Baker <dave@matrix.org> | 2017-03-08 11:37:34 +0000 |
---|---|---|
committer | David Baker <dave@matrix.org> | 2017-03-08 11:37:34 +0000 |
commit | 2e27339add58f71485af873cc70284d0bcc2a6bb (patch) | |
tree | 938270189a119490bcfcfebfeee6473d2b93579e /synapse/rest/client/v2_alpha/account.py | |
parent | Factor out msisdn canonicalisation (diff) | |
download | synapse-2e27339add58f71485af873cc70284d0bcc2a6bb.tar.xz |
Refector out assert_params_in_request
and replace requestEmailToken where we meant requestMsisdnToken
Diffstat (limited to 'synapse/rest/client/v2_alpha/account.py')
-rw-r--r-- | synapse/rest/client/v2_alpha/account.py | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/synapse/rest/client/v2_alpha/account.py b/synapse/rest/client/v2_alpha/account.py index 199af60fc9..9a5e1d871e 100644 --- a/synapse/rest/client/v2_alpha/account.py +++ b/synapse/rest/client/v2_alpha/account.py @@ -18,7 +18,9 @@ from twisted.internet import defer from synapse.api.constants import LoginType from synapse.api.errors import LoginError, SynapseError, Codes -from synapse.http.servlet import RestServlet, parse_json_object_from_request +from synapse.http.servlet import ( + RestServlet, parse_json_object_from_request, assert_params_in_request +) from synapse.util.async import run_on_reactor from synapse.util.msisdn import phone_number_to_msisdn @@ -42,14 +44,9 @@ class EmailPasswordRequestTokenRestServlet(RestServlet): def on_POST(self, request): body = parse_json_object_from_request(request) - required = ['id_server', 'client_secret', 'email', 'send_attempt'] - absent = [] - for k in required: - if k not in body: - absent.append(k) - - if absent: - raise SynapseError(400, "Missing params: %r" % absent, Codes.MISSING_PARAM) + assert_params_in_request(body, [ + 'id_server', 'client_secret', 'email', 'send_attempt' + ]) existingUid = yield self.hs.get_datastore().get_user_id_by_threepid( 'email', body['email'] @@ -74,17 +71,10 @@ class MsisdnPasswordRequestTokenRestServlet(RestServlet): def on_POST(self, request): body = parse_json_object_from_request(request) - required = [ + assert_params_in_request(body,[ 'id_server', 'client_secret', 'country', 'phone_number', 'send_attempt', - ] - absent = [] - for k in required: - if k not in body: - absent.append(k) - - if absent: - raise SynapseError(400, "Missing params: %r" % absent, Codes.MISSING_PARAM) + ]) msisdn = phone_number_to_msisdn(body['country'], body['phone_number']) @@ -95,7 +85,7 @@ class MsisdnPasswordRequestTokenRestServlet(RestServlet): if existingUid is None: raise SynapseError(400, "MSISDN not found", Codes.THREEPID_NOT_FOUND) - ret = yield self.identity_handler.requestEmailToken(**body) + ret = yield self.identity_handler.requestMsisdnToken(**body) defer.returnValue((200, ret)) |