From fef3183461a60715cb5fb0638abcde335c61db82 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 16:40:15 +0100 Subject: [PATCH] Pass back the user_id in the response to /login in case it has changed. Store and use that on the webclient rather than the input field. --- synapse/handlers/login.py | 6 +----- synapse/rest/login.py | 6 ++++++ webclient/login/login-controller.js | 2 +- webclient/login/login.html | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/synapse/handlers/login.py b/synapse/handlers/login.py index 5c7d503a2..0220fa060 100644 --- a/synapse/handlers/login.py +++ b/synapse/handlers/login.py @@ -16,7 +16,6 @@ from twisted.internet import defer from ._base import BaseHandler -from synapse.types import UserID from synapse.api.errors import LoginError, Codes import bcrypt @@ -36,7 +35,7 @@ class LoginHandler(BaseHandler): """Login as the specified user with the specified password. Args: - user (str): The user ID or username. + user (str): The user ID. password (str): The password. Returns: The newly allocated access token. @@ -48,9 +47,6 @@ class LoginHandler(BaseHandler): if not hasattr(self, "reg_handler"): self.reg_handler = self.hs.get_handlers().registration_handler - if not user.startswith('@'): - user = UserID.create_local(user, self.hs).to_string() - # pull out the hash for this user if they exist user_info = yield self.store.get_user_by_id(user_id=user) if not user_info: diff --git a/synapse/rest/login.py b/synapse/rest/login.py index 88a321833..bcf63fd2a 100644 --- a/synapse/rest/login.py +++ b/synapse/rest/login.py @@ -16,6 +16,7 @@ from twisted.internet import defer from synapse.api.errors import SynapseError +from synapse.types import UserID from base import RestServlet, client_path_pattern import json @@ -45,12 +46,17 @@ class LoginRestServlet(RestServlet): @defer.inlineCallbacks def do_password_login(self, login_submission): + if not login_submission["user"].startswith('@'): + login_submission["user"] = UserID.create_local( + login_submission["user"], self.hs).to_string() + handler = self.handlers.login_handler token = yield handler.login( user=login_submission["user"], password=login_submission["password"]) result = { + "user_id": login_submission["user"], # may have changed "access_token": token, "home_server": self.hs.hostname, } diff --git a/webclient/login/login-controller.js b/webclient/login/login-controller.js index 53756be9e..8bd6a4e84 100644 --- a/webclient/login/login-controller.js +++ b/webclient/login/login-controller.js @@ -79,7 +79,7 @@ angular.module('LoginController', ['matrixService']) $scope.feedback = "Login successful."; matrixService.setConfig({ homeserver: $scope.account.homeserver, - user_id: $scope.account.user_id, + user_id: response.data.user_id, access_token: response.data.access_token }); matrixService.saveConfig(); diff --git a/webclient/login/login.html b/webclient/login/login.html index 0fbeeabed..a8b2b1f12 100644 --- a/webclient/login/login.html +++ b/webclient/login/login.html @@ -24,7 +24,7 @@
{{ login_error_msg }}
- +