brings back the functionality in login/register/screens that got lost in @kegsay's refactor. specifically:

1) custom HS/IS urls are now persisted in HTML5 local storage.  As a result, all the login components now distinguish between default HS/IS URLs and custom specified ones again. (
2) custom HS/IS urls are synchronised between the instances of ServerConfig found in the Login, Registration and Forgot Password screens.
3) username are persisted over changing homeserver (but not password, to stop accidentally leaking passwords to the wrong server)
4) correctly interpret a blank URL field as meaning the placeholder text
5) when toggling custom URLs on and off, remember what the custom values were, and use the default URLs if custom mode is not engaged

also, guest access now upholds custom HS/IS URLs found in local storage rather than being limited to the server config ()

also adds assorted comments and improved console debug and a few minor cosmetic changes to the login components.

this commit sponsored by VS27...
This commit is contained in:
Matthew Hodgson 2016-03-06 14:33:36 -05:00
parent b66ca74ede
commit 0bb58dd60c
8 changed files with 177 additions and 75 deletions

View file

@ -85,6 +85,32 @@ module.exports = React.createClass({
};
},
getCurrentHsUrl: function() {
if (MatrixClientPeg.get()) {
return MatrixClientPeg.get().getHomeserverUrl();
}
else if (window.localStorage && window.localStorage.getItem("mx_hs_url")) {
return window.localStorage.getItem("mx_hs_url");
}
else if (this.props.config) {
return this.props.config.default_hs_url
}
return "https://matrix.org";
},
getCurrentIsUrl: function() {
if (MatrixClientPeg.get()) {
return MatrixClientPeg.get().getIdentityServerUrl();
}
else if (window.localStorage && window.localStorage.getItem("mx_is_url")) {
return window.localStorage.getItem("mx_is_url");
}
else if (this.props.config) {
return this.props.config.default_is_url
}
return "https://matrix.org";
},
componentWillMount: function() {
this.favicon = new Favico({animation: 'none'});
},
@ -92,8 +118,8 @@ module.exports = React.createClass({
componentDidMount: function() {
this._autoRegisterAsGuest = false;
if (this.props.enableGuest) {
if (!this.props.config || !this.props.config.default_hs_url) {
console.error("Cannot enable guest access: No supplied config prop for HS/IS URLs");
if (!this.getCurrentHsUrl() || !this.getCurrentIsUrl()) {
console.error("Cannot enable guest access: can't determine HS/IS URLs to use");
}
else if (this.props.startingQueryParams.client_secret && this.props.startingQueryParams.sid) {
console.log("Not registering as guest; registration.");
@ -155,10 +181,10 @@ module.exports = React.createClass({
_registerAsGuest: function() {
var self = this;
var config = this.props.config;
console.log("Doing guest login on %s", config.default_hs_url);
console.log("Doing guest login on %s", this.getCurrentHsUrl());
MatrixClientPeg.replaceUsingUrls(
config.default_hs_url, config.default_is_url
this.getCurrentHsUrl(),
this.getCurrentIsUrl()
);
MatrixClientPeg.get().registerGuest().done(function(creds) {
console.log("Registered as guest: %s", creds.user_id);
@ -166,8 +192,8 @@ module.exports = React.createClass({
self.onLoggedIn({
userId: creds.user_id,
accessToken: creds.access_token,
homeserverUrl: config.default_hs_url,
identityServerUrl: config.default_is_url,
homeserverUrl: self.getCurrentHsUrl(),
identityServerUrl: self.getCurrentIsUrl(),
guest: true
});
}, function(err) {
@ -188,7 +214,12 @@ module.exports = React.createClass({
switch (payload.action) {
case 'logout':
if (window.localStorage) {
// preserve our HS & IS URLs for convenience
var hsUrl = this.getCurrentHsUrl();
var isUrl = this.getCurrentIsUrl();
window.localStorage.clear();
window.localStorage.setItem("mx_hs_url", hsUrl);
window.localStorage.setItem("mx_is_url", isUrl);
}
Notifier.stop();
UserActivity.stop();
@ -711,7 +742,7 @@ module.exports = React.createClass({
}
}
else {
console.error("Unknown screen : %s", screen);
console.info("Ignoring showScreen for '%s'", screen);
}
},
@ -875,6 +906,8 @@ module.exports = React.createClass({
var NewVersionBar = sdk.getComponent('globals.NewVersionBar');
var ForgotPassword = sdk.getComponent('structures.login.ForgotPassword');
// work out the HS URL prompts we should show for
// needs to be before normal PageTypes as you are logged in technically
if (this.state.screen == 'post_registration') {
return (
@ -970,26 +1003,34 @@ module.exports = React.createClass({
username={this.state.upgradeUsername}
disableUsernameChanges={Boolean(this.state.upgradeUsername)}
guestAccessToken={this.state.guestAccessToken}
hsUrl={this.props.config.default_hs_url}
isUrl={this.props.config.default_is_url}
defaultHsUrl={this.props.config.default_hs_url}
defaultIsUrl={this.props.config.default_is_url}
initialHsUrl={this.getCurrentHsUrl()}
initialIsUrl={this.getCurrentIsUrl()}
registrationUrl={this.props.registrationUrl}
onLoggedIn={this.onRegistered}
onLoginClick={this.onLoginClick} />
onLoginClick={this.onLoginClick}
onRegisterClick={this.onRegisterClick} />
);
} else if (this.state.screen == 'forgot_password') {
return (
<ForgotPassword
homeserverUrl={this.props.config.default_hs_url}
identityServerUrl={this.props.config.default_is_url}
onComplete={this.onLoginClick} />
defaultHsUrl={this.props.config.default_hs_url}
defaultIsUrl={this.props.config.default_is_url}
initialHsUrl={this.getCurrentHsUrl()}
initialIsUrl={this.getCurrentIsUrl()}
onComplete={this.onLoginClick}
onLoginClick={this.onLoginClick} />
);
} else {
return (
<Login
onLoggedIn={this.onLoggedIn}
onRegisterClick={this.onRegisterClick}
homeserverUrl={this.props.config.default_hs_url}
identityServerUrl={this.props.config.default_is_url}
defaultHsUrl={this.props.config.default_hs_url}
defaultIsUrl={this.props.config.default_is_url}
initialHsUrl={this.getCurrentHsUrl()}
initialIsUrl={this.getCurrentIsUrl()}
onForgotPasswordClick={this.onForgotPasswordClick}
onLoginAsGuestClick={this.props.enableGuest && this.props.config && this.props.config.default_hs_url ? this._registerAsGuest: undefined}
/>