Change how the default server name and HS URL interact

They are now independent of each other. If both are specified in the config, the user will see an error and be prevented from logging in. The expected behaviour is that when a default server name is given, we do a .well-known lookup to find the default homeserver (and block the UI while we do this to prevent it from using matrix.org while we go out and find more information). If the config specifies just a default homeserver URL however, we don't do anything special.
This commit is contained in:
Travis Ralston 2018-12-07 15:36:49 -07:00
parent 0a32570026
commit 6707186edc
5 changed files with 24 additions and 27 deletions

View file

@ -180,13 +180,6 @@ limitations under the License.
margin-bottom: 12px;
}
.mx_Login_subtext {
display: block;
font-size: 0.8em;
text-align: center;
margin: 10px;
}
.mx_Login_type_container {
display: flex;
margin-bottom: 14px;

View file

@ -298,7 +298,16 @@ export default React.createClass({
// Set up the default URLs (async)
if (this.getDefaultServerName() && !this.getDefaultHsUrl(false)) {
this.setState({loadingDefaultHomeserver: true});
this._tryDiscoverDefaultHomeserver(this.getDefaultServerName());
} else if (this.getDefaultServerName() && this.getDefaultHsUrl(false)) {
// Ideally we would somehow only communicate this to the server admins, but
// given this is at login time we can't really do much besides hope that people
// will check their settings.
this.setState({
defaultServerName: null, // To un-hide any secrets people might be keeping
defaultServerDiscoveryError: _t("Invalid configuration: Cannot supply a default homeserver URL and a default server name"),
});
}
// Set a default HS with query param `hs_url`
@ -1756,13 +1765,20 @@ export default React.createClass({
const state = discovery["m.homeserver"].state;
if (state !== AutoDiscovery.SUCCESS) {
console.error("Failed to discover homeserver on startup:", discovery);
this.setState({defaultServerDiscoveryError: discovery["m.homeserver"].error});
this.setState({
defaultServerDiscoveryError: discovery["m.homeserver"].error,
loadingDefaultHomeserver: false,
});
} else {
const hsUrl = discovery["m.homeserver"].base_url;
const isUrl = discovery["m.identity_server"].state === AutoDiscovery.SUCCESS
? discovery["m.identity_server"].base_url
: "https://vector.im";
this.setState({defaultHsUrl: hsUrl, defaultIsUrl: isUrl});
this.setState({
defaultHsUrl: hsUrl,
defaultIsUrl: isUrl,
loadingDefaultHomeserver: false,
});
}
},
@ -1780,7 +1796,7 @@ export default React.createClass({
render: function() {
// console.log(`Rendering MatrixChat with view ${this.state.view}`);
if (this.state.view === VIEWS.LOADING || this.state.view === VIEWS.LOGGING_IN) {
if (this.state.view === VIEWS.LOADING || this.state.view === VIEWS.LOGGING_IN || this.state.loadingDefaultHomeserver) {
const Spinner = sdk.getComponent('elements.Spinner');
return (
<div className="mx_MatrixChat_splash">

View file

@ -470,9 +470,6 @@ module.exports = React.createClass({
_renderPasswordStep: function() {
const PasswordLogin = sdk.getComponent('login.PasswordLogin');
const hsName = this.state.enteredHomeserverUrl === this.props.defaultHsUrl
? this.props.defaultServerName
: null;
return (
<PasswordLogin
onSubmit={this.onPasswordLogin}
@ -487,7 +484,7 @@ module.exports = React.createClass({
onForgotPasswordClick={this.props.onForgotPasswordClick}
loginIncorrect={this.state.loginIncorrect}
hsUrl={this.state.enteredHomeserverUrl}
hsName={hsName}
hsName={this.props.defaultServerName}
/>
);
},

View file

@ -252,21 +252,12 @@ class PasswordLogin extends React.Component {
}
let matrixIdText = _t('Matrix ID');
let matrixIdSubtext = null;
if (this.props.hsName) {
matrixIdText = _t('%(serverName)s Matrix ID', {serverName: this.props.hsName});
}
if (this.props.hsUrl) {
} else {
try {
const parsedHsUrl = new URL(this.props.hsUrl);
if (!this.props.hsName) {
matrixIdText = _t('%(serverName)s Matrix ID', {serverName: parsedHsUrl.hostname});
} else if (parsedHsUrl.hostname !== this.props.hsName) {
matrixIdSubtext = _t('%(serverName)s is located at %(homeserverUrl)s', {
serverName: this.props.hsName,
homeserverUrl: this.props.hsUrl,
});
}
matrixIdText = _t('%(serverName)s Matrix ID', {serverName: parsedHsUrl.hostname});
} catch (e) {
// ignore
}
@ -304,7 +295,6 @@ class PasswordLogin extends React.Component {
<div>
<form onSubmit={this.onSubmitForm}>
{ loginType }
<span className="mx_Login_subtext">{ matrixIdSubtext }</span>
{ loginField }
<input className={pwFieldClass} ref={(e) => {this._passwordField = e;}} type="password"
name="password"

View file

@ -721,8 +721,8 @@
"User name": "User name",
"Mobile phone number": "Mobile phone number",
"Forgot your password?": "Forgot your password?",
"Matrix ID": "Matrix ID",
"%(serverName)s Matrix ID": "%(serverName)s Matrix ID",
"%(serverName)s is located at %(homeserverUrl)s": "%(serverName)s is located at %(homeserverUrl)s",
"Sign in with": "Sign in with",
"Email address": "Email address",
"Sign in": "Sign in",
@ -1114,6 +1114,7 @@
"You are currently using Riot anonymously as a guest.": "You are currently using Riot anonymously as a guest.",
"If you would like to create a Matrix account you can <a>register</a> now.": "If you would like to create a Matrix account you can <a>register</a> now.",
"Login": "Login",
"Invalid configuration: Cannot supply a default homeserver URL and a default server name": "Invalid configuration: Cannot supply a default homeserver URL and a default server name",
"Failed to reject invitation": "Failed to reject invitation",
"This room is not public. You will not be able to rejoin without an invite.": "This room is not public. You will not be able to rejoin without an invite.",
"Are you sure you want to leave the room '%(roomName)s'?": "Are you sure you want to leave the room '%(roomName)s'?",