mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 05:55:00 +08:00
Shift loginIncorrect into state
and consequently make setErrorTextFromError into setStateFromError
This commit is contained in:
parent
476f69cbec
commit
bb3a7725db
@ -52,8 +52,8 @@ module.exports = React.createClass({displayName: 'Login',
|
|||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
busy: false,
|
busy: false,
|
||||||
error: null, // The error as-is from the login request
|
|
||||||
errorText: null,
|
errorText: null,
|
||||||
|
loginIncorrect: false,
|
||||||
enteredHomeserverUrl: this.props.customHsUrl || this.props.defaultHsUrl,
|
enteredHomeserverUrl: this.props.customHsUrl || this.props.defaultHsUrl,
|
||||||
enteredIdentityServerUrl: this.props.customIsUrl || this.props.defaultIsUrl,
|
enteredIdentityServerUrl: this.props.customIsUrl || this.props.defaultIsUrl,
|
||||||
|
|
||||||
@ -70,15 +70,14 @@ module.exports = React.createClass({displayName: 'Login',
|
|||||||
var self = this;
|
var self = this;
|
||||||
self.setState({
|
self.setState({
|
||||||
busy: true,
|
busy: true,
|
||||||
error: null,
|
|
||||||
errorText: null,
|
errorText: null,
|
||||||
|
loginIncorrect: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
this._loginLogic.loginViaPassword(username, password).then(function(data) {
|
this._loginLogic.loginViaPassword(username, password).then(function(data) {
|
||||||
self.props.onLoggedIn(data);
|
self.props.onLoggedIn(data);
|
||||||
}, function(error) {
|
}, function(error) {
|
||||||
self.setState({error: error});
|
self._setStateFromError(error);
|
||||||
self._setErrorTextFromError(error);
|
|
||||||
}).finally(function() {
|
}).finally(function() {
|
||||||
self.setState({
|
self.setState({
|
||||||
busy: false
|
busy: false
|
||||||
@ -124,7 +123,7 @@ module.exports = React.createClass({displayName: 'Login',
|
|||||||
// logins so let's skip that for now).
|
// logins so let's skip that for now).
|
||||||
loginLogic.chooseFlow(0);
|
loginLogic.chooseFlow(0);
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
self._setErrorTextFromError(err);
|
self._setStateFromError(err);
|
||||||
}).finally(function() {
|
}).finally(function() {
|
||||||
self.setState({
|
self.setState({
|
||||||
busy: false
|
busy: false
|
||||||
@ -135,7 +134,8 @@ module.exports = React.createClass({displayName: 'Login',
|
|||||||
enteredHomeserverUrl: hsUrl,
|
enteredHomeserverUrl: hsUrl,
|
||||||
enteredIdentityServerUrl: isUrl,
|
enteredIdentityServerUrl: isUrl,
|
||||||
busy: true,
|
busy: true,
|
||||||
errorText: null // reset err messages
|
errorText: null, // reset err messages
|
||||||
|
loginIncorrect: false,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -143,20 +143,25 @@ module.exports = React.createClass({displayName: 'Login',
|
|||||||
return this._loginLogic ? this._loginLogic.getCurrentFlowStep() : null
|
return this._loginLogic ? this._loginLogic.getCurrentFlowStep() : null
|
||||||
},
|
},
|
||||||
|
|
||||||
_setErrorTextFromError: function(err) {
|
_setStateFromError: function(err) {
|
||||||
if (err.friendlyText) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
errorText: err.friendlyText
|
errorText: this._errorTextFromError(err),
|
||||||
|
// https://matrix.org/jira/browse/SYN-744
|
||||||
|
loginIncorrect: err.httpStatus == 401 || err.httpStatus == 403
|
||||||
});
|
});
|
||||||
return;
|
},
|
||||||
|
|
||||||
|
_errorTextFromError(err) {
|
||||||
|
if (err.friendlyText) {
|
||||||
|
return err.friendlyText;
|
||||||
}
|
}
|
||||||
|
|
||||||
var errCode = err.errcode;
|
let errCode = err.errcode;
|
||||||
if (!errCode && err.httpStatus) {
|
if (!errCode && err.httpStatus) {
|
||||||
errCode = "HTTP " + err.httpStatus;
|
errCode = "HTTP " + err.httpStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
var errorText = "Error: Problem communicating with the given homeserver " +
|
let errorText = "Error: Problem communicating with the given homeserver " +
|
||||||
(errCode ? "(" + errCode + ")" : "")
|
(errCode ? "(" + errCode + ")" : "")
|
||||||
|
|
||||||
if (err.cors === 'rejected') {
|
if (err.cors === 'rejected') {
|
||||||
@ -177,26 +182,19 @@ module.exports = React.createClass({displayName: 'Login',
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
return errorText;
|
||||||
errorText: errorText
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
componentForStep: function(step) {
|
componentForStep: function(step) {
|
||||||
switch (step) {
|
switch (step) {
|
||||||
case 'm.login.password':
|
case 'm.login.password':
|
||||||
// https://matrix.org/jira/browse/SYN-744
|
|
||||||
const loginIncorrect = (
|
|
||||||
this.state.error &&
|
|
||||||
(this.state.error.httpStatus == 401 || this.state.error.httpStatus == 403)
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<PasswordLogin
|
<PasswordLogin
|
||||||
onSubmit={this.onPasswordLogin}
|
onSubmit={this.onPasswordLogin}
|
||||||
initialUsername={this.state.username}
|
initialUsername={this.state.username}
|
||||||
onUsernameChanged={this.onUsernameChanged}
|
onUsernameChanged={this.onUsernameChanged}
|
||||||
onForgotPasswordClick={this.props.onForgotPasswordClick}
|
onForgotPasswordClick={this.props.onForgotPasswordClick}
|
||||||
loginIncorrect={loginIncorrect}
|
loginIncorrect={this.state.loginIncorrect}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'm.login.cas':
|
case 'm.login.cas':
|
||||||
|
Loading…
Reference in New Issue
Block a user