Introduce an onUsernameBlur and fix hostname parsing

This commit is contained in:
Travis Ralston 2018-11-21 14:13:56 -07:00
parent 6f0f930e0a
commit 4cfefe4c3c
3 changed files with 21 additions and 5 deletions

View file

@ -232,11 +232,24 @@ module.exports = React.createClass({
}).done();
},
onUsernameChanged: function(username, endOfInput) {
onUsernameChanged: function(username) {
this.setState({ username: username });
if (username[0] === "@" && endOfInput) {
},
onUsernameBlur: function(username) {
this.setState({ username: username });
if (username[0] === "@") {
const serverName = username.split(':').slice(1).join(':');
this._tryWellKnownDiscovery(serverName);
try {
// we have to append 'https://' to make the URL constructor happy
// otherwise we get things like 'protocol: matrix.org, pathname: 8448'
const url = new URL("https://" + serverName);
this._tryWellKnownDiscovery(url.hostname);
} catch (e) {
console.error("Problem parsing URL or unhandled error doing .well-known discovery");
console.error(e);
this.setState({discoveryError: _t("Failed to perform homeserver discovery")});
}
}
},
@ -531,6 +544,7 @@ module.exports = React.createClass({
initialPhoneCountry={this.state.phoneCountry}
initialPhoneNumber={this.state.phoneNumber}
onUsernameChanged={this.onUsernameChanged}
onUsernameBlur={this.onUsernameBlur}
onPhoneCountryChanged={this.onPhoneCountryChanged}
onPhoneNumberChanged={this.onPhoneNumberChanged}
onForgotPasswordClick={this.props.onForgotPasswordClick}

View file

@ -30,6 +30,7 @@ class PasswordLogin extends React.Component {
static defaultProps = {
onError: function() {},
onUsernameChanged: function() {},
onUsernameBlur: function() {},
onPasswordChanged: function() {},
onPhoneCountryChanged: function() {},
onPhoneNumberChanged: function() {},
@ -122,11 +123,11 @@ class PasswordLogin extends React.Component {
onUsernameChanged(ev) {
this.setState({username: ev.target.value});
this.props.onUsernameChanged(ev.target.value, false);
this.props.onUsernameChanged(ev.target.value);
}
onUsernameBlur(ev) {
this.props.onUsernameChanged(this.state.username, true);
this.props.onUsernameBlur(this.state.username);
}
onLoginTypeChange(loginType) {

View file

@ -1288,6 +1288,7 @@
"Incorrect username and/or password.": "Incorrect username and/or password.",
"Please note you are logging into the %(hs)s server, not matrix.org.": "Please note you are logging into the %(hs)s server, not matrix.org.",
"Guest access is disabled on this Home Server.": "Guest access is disabled on this Home Server.",
"Failed to perform homeserver discovery": "Failed to perform homeserver discovery",
"The phone number entered looks invalid": "The phone number entered looks invalid",
"Invalid homeserver discovery response": "Invalid homeserver discovery response",
"Cannot find homeserver": "Cannot find homeserver",