mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-22 01:25:44 +03:00
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.
This commit is contained in:
parent
ca3747fb2f
commit
fef3183461
4 changed files with 9 additions and 7 deletions
|
@ -16,7 +16,6 @@
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from ._base import BaseHandler
|
from ._base import BaseHandler
|
||||||
from synapse.types import UserID
|
|
||||||
from synapse.api.errors import LoginError, Codes
|
from synapse.api.errors import LoginError, Codes
|
||||||
|
|
||||||
import bcrypt
|
import bcrypt
|
||||||
|
@ -36,7 +35,7 @@ class LoginHandler(BaseHandler):
|
||||||
"""Login as the specified user with the specified password.
|
"""Login as the specified user with the specified password.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user (str): The user ID or username.
|
user (str): The user ID.
|
||||||
password (str): The password.
|
password (str): The password.
|
||||||
Returns:
|
Returns:
|
||||||
The newly allocated access token.
|
The newly allocated access token.
|
||||||
|
@ -48,9 +47,6 @@ class LoginHandler(BaseHandler):
|
||||||
if not hasattr(self, "reg_handler"):
|
if not hasattr(self, "reg_handler"):
|
||||||
self.reg_handler = self.hs.get_handlers().registration_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
|
# pull out the hash for this user if they exist
|
||||||
user_info = yield self.store.get_user_by_id(user_id=user)
|
user_info = yield self.store.get_user_by_id(user_id=user)
|
||||||
if not user_info:
|
if not user_info:
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.errors import SynapseError
|
from synapse.api.errors import SynapseError
|
||||||
|
from synapse.types import UserID
|
||||||
from base import RestServlet, client_path_pattern
|
from base import RestServlet, client_path_pattern
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
@ -45,12 +46,17 @@ class LoginRestServlet(RestServlet):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def do_password_login(self, login_submission):
|
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
|
handler = self.handlers.login_handler
|
||||||
token = yield handler.login(
|
token = yield handler.login(
|
||||||
user=login_submission["user"],
|
user=login_submission["user"],
|
||||||
password=login_submission["password"])
|
password=login_submission["password"])
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
|
"user_id": login_submission["user"], # may have changed
|
||||||
"access_token": token,
|
"access_token": token,
|
||||||
"home_server": self.hs.hostname,
|
"home_server": self.hs.hostname,
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ angular.module('LoginController', ['matrixService'])
|
||||||
$scope.feedback = "Login successful.";
|
$scope.feedback = "Login successful.";
|
||||||
matrixService.setConfig({
|
matrixService.setConfig({
|
||||||
homeserver: $scope.account.homeserver,
|
homeserver: $scope.account.homeserver,
|
||||||
user_id: $scope.account.user_id,
|
user_id: response.data.user_id,
|
||||||
access_token: response.data.access_token
|
access_token: response.data.access_token
|
||||||
});
|
});
|
||||||
matrixService.saveConfig();
|
matrixService.saveConfig();
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<!-- Login with an registered user -->
|
<!-- Login with an registered user -->
|
||||||
<div>{{ login_error_msg }} </div>
|
<div>{{ login_error_msg }} </div>
|
||||||
<div>
|
<div>
|
||||||
<input id="user_id" size="70" type="text" auto-focus ng-model="account.user_id" placeholder="User ID (ex:@bob:localhost)"/>
|
<input id="user_id" size="70" type="text" auto-focus ng-model="account.user_id" placeholder="User ID (ex:@bob:localhost or bob)"/>
|
||||||
<br />
|
<br />
|
||||||
<input id="password" size="70" type="password" ng-model="account.password" placeholder="Password"/><br />
|
<input id="password" size="70" type="password" ng-model="account.password" placeholder="Password"/><br />
|
||||||
<br/>
|
<br/>
|
||||||
|
|
Loading…
Reference in a new issue