From c75add6ec87cb548b5cc74b7e6e0c56d78d5eae9 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 11:52:56 +0100 Subject: Added a urls module for keeping client and federation prefixes. --- synapse/handlers/directory.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'synapse/handlers') diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py index df98e39f69..7c89150d99 100644 --- a/synapse/handlers/directory.py +++ b/synapse/handlers/directory.py @@ -20,17 +20,11 @@ from ._base import BaseHandler from synapse.api.errors import SynapseError import logging -import json -import urllib logger = logging.getLogger(__name__) -# TODO(erikj): This needs to be factored out somewere -PREFIX = "/matrix/client/api/v1" - - class DirectoryHandler(BaseHandler): def __init__(self, hs): -- cgit 1.4.1 From 0fa05ea3314779e3e01e87c0240331825b8115a3 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Thu, 14 Aug 2014 14:15:54 +0100 Subject: Round Presence mtime and mtime_age to nearest msec; avoids floats for msec values over the wire --- synapse/handlers/presence.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'synapse/handlers') diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 8bdb0fe5c7..351ff305dc 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -177,7 +177,9 @@ class PresenceHandler(BaseHandler): state = self._get_or_offline_usercache(target_user).get_state() if "mtime" in state: - state["mtime_age"] = self.clock.time_msec() - state.pop("mtime") + state["mtime_age"] = int( + self.clock.time_msec() - state.pop("mtime") + ) defer.returnValue(state) @defer.inlineCallbacks @@ -367,7 +369,9 @@ class PresenceHandler(BaseHandler): p["observed_user"] = observed_user p.update(self._get_or_offline_usercache(observed_user).get_state()) if "mtime" in p: - p["mtime_age"] = self.clock.time_msec() - p.pop("mtime") + p["mtime_age"] = int( + self.clock.time_msec() - p.pop("mtime") + ) defer.returnValue(presence) @@ -560,7 +564,9 @@ class PresenceHandler(BaseHandler): if "mtime" in state: state = dict(state) - state["mtime_age"] = self.clock.time_msec() - state.pop("mtime") + state["mtime_age"] = int( + self.clock.time_msec() - state.pop("mtime") + ) yield self.federation.send_edu( destination=destination, @@ -598,7 +604,9 @@ class PresenceHandler(BaseHandler): del state["user_id"] if "mtime_age" in state: - state["mtime"] = self.clock.time_msec() - state.pop("mtime_age") + state["mtime"] = int( + self.clock.time_msec() - state.pop("mtime_age") + ) statuscache = self._get_or_make_usercache(user) @@ -720,6 +728,8 @@ class UserPresenceCache(object): content["user_id"] = user.to_string() if "mtime" in content: - content["mtime_age"] = clock.time_msec() - content.pop("mtime") + content["mtime_age"] = int( + clock.time_msec() - content.pop("mtime") + ) return {"type": "m.presence", "content": content} -- cgit 1.4.1 From 5a5f37ca17fdee8149ec0f6ce78f83259ed9d530 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 14:29:01 +0100 Subject: Send forbidden codes when doing login attempts. --- synapse/handlers/login.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'synapse/handlers') diff --git a/synapse/handlers/login.py b/synapse/handlers/login.py index ca69829d77..0220fa0604 100644 --- a/synapse/handlers/login.py +++ b/synapse/handlers/login.py @@ -16,7 +16,7 @@ from twisted.internet import defer from ._base import BaseHandler -from synapse.api.errors import LoginError +from synapse.api.errors import LoginError, Codes import bcrypt import logging @@ -51,7 +51,7 @@ class LoginHandler(BaseHandler): user_info = yield self.store.get_user_by_id(user_id=user) if not user_info: logger.warn("Attempted to login as %s but they do not exist.", user) - raise LoginError(403, "") + raise LoginError(403, "", errcode=Codes.FORBIDDEN) stored_hash = user_info[0]["password_hash"] if bcrypt.checkpw(password, stored_hash): @@ -62,4 +62,4 @@ class LoginHandler(BaseHandler): defer.returnValue(token) else: logger.warn("Failed password login for user %s", user) - raise LoginError(403, "") \ No newline at end of file + raise LoginError(403, "", errcode=Codes.FORBIDDEN) \ No newline at end of file -- cgit 1.4.1 From 53147e5ae4c02f1d9bc4a4b5242a8ac1f476b1b8 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Thu, 14 Aug 2014 16:22:08 +0100 Subject: Reflect user's messages up to themselves before pushing it to federatoin; also release roomlock before touching federation so we don't halt progress on the world --- synapse/handlers/room.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'synapse/handlers') diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index eae40765b3..5d0379254b 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -94,10 +94,10 @@ class MessageHandler(BaseHandler): event.room_id ) - yield self.hs.get_federation().handle_new_event(event) - self.notifier.on_new_room_event(event, store_id) + yield self.hs.get_federation().handle_new_event(event) + @defer.inlineCallbacks def get_messages(self, user_id=None, room_id=None, pagin_config=None, feedback=False): -- cgit 1.4.1 From ca3747fb2f9a1e2e6d5d9e55cd0760e373b57a90 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 16:29:24 +0100 Subject: hs: Make /login accept full user IDs or just local parts. webclient: Only enable Register button when both password fields match. --- synapse/handlers/login.py | 6 +++++- webclient/login/login-controller.js | 6 ------ webclient/login/login.html | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'synapse/handlers') diff --git a/synapse/handlers/login.py b/synapse/handlers/login.py index 0220fa0604..5c7d503a24 100644 --- a/synapse/handlers/login.py +++ b/synapse/handlers/login.py @@ -16,6 +16,7 @@ from twisted.internet import defer from ._base import BaseHandler +from synapse.types import UserID from synapse.api.errors import LoginError, Codes import bcrypt @@ -35,7 +36,7 @@ class LoginHandler(BaseHandler): """Login as the specified user with the specified password. Args: - user (str): The user ID. + user (str): The user ID or username. password (str): The password. Returns: The newly allocated access token. @@ -47,6 +48,9 @@ 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/webclient/login/login-controller.js b/webclient/login/login-controller.js index 826a533873..53756be9ea 100644 --- a/webclient/login/login-controller.js +++ b/webclient/login/login-controller.js @@ -68,12 +68,6 @@ angular.module('LoginController', ['matrixService']) }; $scope.login = function() { - if ($scope.account.user_id.indexOf("@") !== 0) { - // technically should be the host of account.homeserver - $scope.account.user_id = "@" + $scope.account.user_id + ":" + - $location.host() - } - matrixService.setConfig({ homeserver: $scope.account.homeserver, user_id: $scope.account.user_id diff --git a/webclient/login/login.html b/webclient/login/login.html index f02dde89a6..0fbeeabed7 100644 --- a/webclient/login/login.html +++ b/webclient/login/login.html @@ -15,7 +15,7 @@

- +
-- cgit 1.4.1 From fef3183461a60715cb5fb0638abcde335c61db82 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 16:40:15 +0100 Subject: 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(-) (limited to 'synapse/handlers') diff --git a/synapse/handlers/login.py b/synapse/handlers/login.py index 5c7d503a24..0220fa0604 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 88a3218332..bcf63fd2ab 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 53756be9ea..8bd6a4e84f 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 0fbeeabed7..a8b2b1f12d 100644 --- a/webclient/login/login.html +++ b/webclient/login/login.html @@ -24,7 +24,7 @@
{{ login_error_msg }}
- +


-- cgit 1.4.1