From 5097c2671d6b3513c6e237e9a353e65793f25d51 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 1 Jul 2019 23:25:47 +0100 Subject: [PATCH 1/2] Factor out some redundant code in the login impl Also fixes a redundant access_token which was generated during jwt login. --- changelog.d/5638.misc | 1 + synapse/rest/client/v1/login.py | 49 +++++++-------------------------- 2 files changed, 11 insertions(+), 39 deletions(-) create mode 100644 changelog.d/5638.misc diff --git a/changelog.d/5638.misc b/changelog.d/5638.misc new file mode 100644 index 000000000000..413b13128c6f --- /dev/null +++ b/changelog.d/5638.misc @@ -0,0 +1 @@ +Factor out some redundant code in the login implementation. diff --git a/synapse/rest/client/v1/login.py b/synapse/rest/client/v1/login.py index f96117823557..b13043cc6408 100644 --- a/synapse/rest/client/v1/login.py +++ b/synapse/rest/client/v1/login.py @@ -283,19 +283,7 @@ def do_token_login(self, login_submission): yield auth_handler.validate_short_term_login_token_and_get_user_id(token) ) - device_id = login_submission.get("device_id") - initial_display_name = login_submission.get("initial_device_display_name") - device_id, access_token = yield self.registration_handler.register_device( - user_id, device_id, initial_display_name - ) - - result = { - "user_id": user_id, # may have changed - "access_token": access_token, - "home_server": self.hs.hostname, - "device_id": device_id, - } - + result = yield self._register_device_with_callback(user_id, login_submission) defer.returnValue(result) @defer.inlineCallbacks @@ -323,35 +311,18 @@ def do_jwt_login(self, login_submission): raise LoginError(401, "Invalid JWT", errcode=Codes.UNAUTHORIZED) user_id = UserID(user, self.hs.hostname).to_string() - device_id = login_submission.get("device_id") - initial_display_name = login_submission.get("initial_device_display_name") - - auth_handler = self.auth_handler - registered_user_id = yield auth_handler.check_user_exists(user_id) - if registered_user_id: - device_id, access_token = yield self.registration_handler.register_device( - registered_user_id, device_id, initial_display_name - ) - result = { - "user_id": registered_user_id, - "access_token": access_token, - "home_server": self.hs.hostname, - } - else: - user_id, access_token = ( - yield self.registration_handler.register(localpart=user) - ) - device_id, access_token = yield self.registration_handler.register_device( - user_id, device_id, initial_display_name + registered_user_id = yield self.auth_handler.check_user_exists(user_id) + if not registered_user_id: + registered_user_id, _ = ( + yield self.registration_handler.register( + localpart=user, generate_token=False + ) ) - result = { - "user_id": user_id, # may have changed - "access_token": access_token, - "home_server": self.hs.hostname, - } - + result = yield self._register_device_with_callback( + registered_user_id, login_submission + ) defer.returnValue(result) From 71539841261aeb44abbf01075ec465df0a94303e Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 8 Jul 2019 14:30:02 +0100 Subject: [PATCH 2/2] changelog --- changelog.d/{5638.misc => 5639.misc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog.d/{5638.misc => 5639.misc} (100%) diff --git a/changelog.d/5638.misc b/changelog.d/5639.misc similarity index 100% rename from changelog.d/5638.misc rename to changelog.d/5639.misc