Introduce a default_server_name for aesthetics and rework .well-known

Fixes https://github.com/vector-im/riot-web/issues/7724

The `default_server_name` from the config gets displayed in the "Login with my [server] matrix ID" dropdown when the default server is being used. At this point, we also discourage the use of the `default_hs_url` and `default_is_url` options because we do an implicit .well-known lookup to configure the client based on the `default_server_name`. If the URLs are still present in the config, we'll honour them and won't do a .well-known lookup when the URLs are mixed with the new server_name option. Users will be warned if the `default_server_name` does not match the `default_hs_url` if both are supplied. Users are additionally prevented from logging in, registering, and resetting their password if the implicit .well-known check fails - this is to prevent people from doing actions against the wrong homeserver.

This relies on https://github.com/matrix-org/matrix-js-sdk/pull/799 as we now do auto discovery in two places. Instead of bringing the .well-known out to its own utility class in the react-sdk, we might as well drag it out to the js-sdk.
This commit is contained in:
Travis Ralston 2018-12-04 23:34:57 -07:00
parent c0ef2f7df3
commit 633be5061c
7 changed files with 166 additions and 118 deletions

View file

@ -40,6 +40,7 @@ class PasswordLogin extends React.Component {
initialPassword: "",
loginIncorrect: false,
hsDomain: "",
hsName: null,
}
constructor(props) {
@ -250,13 +251,24 @@ class PasswordLogin extends React.Component {
);
}
let matrixIdText = '';
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) {
try {
const parsedHsUrl = new URL(this.props.hsUrl);
matrixIdText = _t('%(serverName)s Matrix ID', {serverName: parsedHsUrl.hostname});
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,
});
}
} catch (e) {
// pass
// ignore
}
}
@ -292,6 +304,7 @@ 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"
@ -325,6 +338,7 @@ PasswordLogin.propTypes = {
onPhoneNumberChanged: PropTypes.func,
onPasswordChanged: PropTypes.func,
loginIncorrect: PropTypes.bool,
hsName: PropTypes.string,
};
module.exports = PasswordLogin;