diff options
author | David Baker <dbkr@users.noreply.github.com> | 2015-08-20 11:15:42 +0100 |
---|---|---|
committer | David Baker <dbkr@users.noreply.github.com> | 2015-08-20 11:15:42 +0100 |
commit | be27d8180872e9b36e92a6fc27b0fba755b7ef89 (patch) | |
tree | 9c1218741d587449e45dc5949d3ec5720cbd34e7 | |
parent | Merge pull request #211 from matrix-org/email_in_use (diff) | |
parent | Comma comma comma comma comma chameleon (diff) | |
download | synapse-be27d8180872e9b36e92a6fc27b0fba755b7ef89.tar.xz |
Merge pull request #234 from matrix-org/email_login
Support logging in with email addresses (or other threepids)
-rw-r--r-- | synapse/rest/client/v1/login.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/synapse/rest/client/v1/login.py b/synapse/rest/client/v1/login.py index 694072693d..0d5eafd0fa 100644 --- a/synapse/rest/client/v1/login.py +++ b/synapse/rest/client/v1/login.py @@ -74,16 +74,23 @@ class LoginRestServlet(ClientV1RestServlet): @defer.inlineCallbacks def do_password_login(self, login_submission): - if not login_submission["user"].startswith('@'): - login_submission["user"] = UserID.create( - login_submission["user"], self.hs.hostname).to_string() + if 'medium' in login_submission and 'address' in login_submission: + user_id = yield self.hs.get_datastore().get_user_id_by_threepid( + login_submission['medium'], login_submission['address'] + ) + else: + user_id = login_submission['user'] + + if not user_id.startswith('@'): + user_id = UserID.create( + user_id, self.hs.hostname).to_string() token = yield self.handlers.auth_handler.login_with_password( - user_id=login_submission["user"], + user_id=user_id, password=login_submission["password"]) result = { - "user_id": login_submission["user"], # may have changed + "user_id": user_id, # may have changed "access_token": token, "home_server": self.hs.hostname, } |