mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 12:28:50 +03:00
Merge pull request #1633 from matrix-org/rav/handle_login_flows_better
Ignore unrecognised login flows
This commit is contained in:
commit
4a20185d64
2 changed files with 77 additions and 39 deletions
|
@ -76,6 +76,14 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
this._unmounted = false;
|
this._unmounted = false;
|
||||||
|
|
||||||
|
// map from login step type to a function which will render a control
|
||||||
|
// letting you do that login type
|
||||||
|
this._stepRendererMap = {
|
||||||
|
'm.login.password': this._renderPasswordStep,
|
||||||
|
'm.login.cas': this._renderCasStep,
|
||||||
|
};
|
||||||
|
|
||||||
this._initLoginLogic();
|
this._initLoginLogic();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -217,13 +225,29 @@ module.exports = React.createClass({
|
||||||
loginIncorrect: false,
|
loginIncorrect: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
loginLogic.getFlows().then(function(flows) {
|
loginLogic.getFlows().then((flows) => {
|
||||||
// old behaviour was to always use the first flow without presenting
|
// look for a flow where we understand all of the steps.
|
||||||
// options. This works in most cases (we don't have a UI for multiple
|
for (let i = 0; i < flows.length; i++ ) {
|
||||||
// logins so let's skip that for now).
|
if (!this._isSupportedFlow(flows[i])) {
|
||||||
loginLogic.chooseFlow(0);
|
continue;
|
||||||
self.setState({
|
}
|
||||||
currentFlow: self._getCurrentFlowStep(),
|
|
||||||
|
// we just pick the first flow where we support all the
|
||||||
|
// steps. (we don't have a UI for multiple logins so let's skip
|
||||||
|
// that for now).
|
||||||
|
loginLogic.chooseFlow(i);
|
||||||
|
this.setState({
|
||||||
|
currentFlow: this._getCurrentFlowStep(),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// we got to the end of the list without finding a suitable
|
||||||
|
// flow.
|
||||||
|
this.setState({
|
||||||
|
errorText: _t(
|
||||||
|
"This homeserver doesn't offer any login flows which are " +
|
||||||
|
"supported by this client.",
|
||||||
|
),
|
||||||
});
|
});
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
self.setState({
|
self.setState({
|
||||||
|
@ -237,6 +261,16 @@ module.exports = React.createClass({
|
||||||
}).done();
|
}).done();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_isSupportedFlow: function(flow) {
|
||||||
|
// technically the flow can have multiple steps, but no one does this
|
||||||
|
// for login and loginLogic doesn't support it so we can ignore it.
|
||||||
|
if (!this._stepRendererMap[flow.type]) {
|
||||||
|
console.log("Skipping flow", flow, "due to unsupported login type", flow.type);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
_getCurrentFlowStep: function() {
|
_getCurrentFlowStep: function() {
|
||||||
return this._loginLogic ? this._loginLogic.getCurrentFlowStep() : null;
|
return this._loginLogic ? this._loginLogic.getCurrentFlowStep() : null;
|
||||||
},
|
},
|
||||||
|
@ -276,38 +310,42 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
componentForStep: function(step) {
|
componentForStep: function(step) {
|
||||||
switch (step) {
|
if (!step) {
|
||||||
case 'm.login.password':
|
return null;
|
||||||
const PasswordLogin = sdk.getComponent('login.PasswordLogin');
|
|
||||||
return (
|
|
||||||
<PasswordLogin
|
|
||||||
onSubmit={this.onPasswordLogin}
|
|
||||||
initialUsername={this.state.username}
|
|
||||||
initialPhoneCountry={this.state.phoneCountry}
|
|
||||||
initialPhoneNumber={this.state.phoneNumber}
|
|
||||||
onUsernameChanged={this.onUsernameChanged}
|
|
||||||
onPhoneCountryChanged={this.onPhoneCountryChanged}
|
|
||||||
onPhoneNumberChanged={this.onPhoneNumberChanged}
|
|
||||||
onForgotPasswordClick={this.props.onForgotPasswordClick}
|
|
||||||
loginIncorrect={this.state.loginIncorrect}
|
|
||||||
hsUrl={this.state.enteredHomeserverUrl}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
case 'm.login.cas':
|
|
||||||
const CasLogin = sdk.getComponent('login.CasLogin');
|
|
||||||
return (
|
|
||||||
<CasLogin onSubmit={this.onCasLogin} />
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
if (!step) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{ _t('Sorry, this homeserver is using a login which is not recognised ') }({ step })
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stepRenderer = this._stepRendererMap[step];
|
||||||
|
|
||||||
|
if (stepRenderer) {
|
||||||
|
return stepRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
_renderPasswordStep: function() {
|
||||||
|
const PasswordLogin = sdk.getComponent('login.PasswordLogin');
|
||||||
|
return (
|
||||||
|
<PasswordLogin
|
||||||
|
onSubmit={this.onPasswordLogin}
|
||||||
|
initialUsername={this.state.username}
|
||||||
|
initialPhoneCountry={this.state.phoneCountry}
|
||||||
|
initialPhoneNumber={this.state.phoneNumber}
|
||||||
|
onUsernameChanged={this.onUsernameChanged}
|
||||||
|
onPhoneCountryChanged={this.onPhoneCountryChanged}
|
||||||
|
onPhoneNumberChanged={this.onPhoneNumberChanged}
|
||||||
|
onForgotPasswordClick={this.props.onForgotPasswordClick}
|
||||||
|
loginIncorrect={this.state.loginIncorrect}
|
||||||
|
hsUrl={this.state.enteredHomeserverUrl}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
_renderCasStep: function() {
|
||||||
|
const CasLogin = sdk.getComponent('login.CasLogin');
|
||||||
|
return (
|
||||||
|
<CasLogin onSubmit={this.onCasLogin} />
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
_onLanguageChange: function(newLang) {
|
_onLanguageChange: function(newLang) {
|
||||||
|
|
|
@ -862,7 +862,7 @@
|
||||||
"Error: Problem communicating with the given homeserver.": "Error: Problem communicating with the given homeserver.",
|
"Error: Problem communicating with the given homeserver.": "Error: Problem communicating with the given homeserver.",
|
||||||
"Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or <a>enable unsafe scripts</a>.": "Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or <a>enable unsafe scripts</a>.",
|
"Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or <a>enable unsafe scripts</a>.": "Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or <a>enable unsafe scripts</a>.",
|
||||||
"Can't connect to homeserver - please check your connectivity, ensure your <a>homeserver's SSL certificate</a> is trusted, and that a browser extension is not blocking requests.": "Can't connect to homeserver - please check your connectivity, ensure your <a>homeserver's SSL certificate</a> is trusted, and that a browser extension is not blocking requests.",
|
"Can't connect to homeserver - please check your connectivity, ensure your <a>homeserver's SSL certificate</a> is trusted, and that a browser extension is not blocking requests.": "Can't connect to homeserver - please check your connectivity, ensure your <a>homeserver's SSL certificate</a> is trusted, and that a browser extension is not blocking requests.",
|
||||||
"Sorry, this homeserver is using a login which is not recognised ": "Sorry, this homeserver is using a login which is not recognised ",
|
"This homeserver doesn't offer any login flows which are supported by this client.": "This homeserver doesn't offer any login flows which are supported by this client.",
|
||||||
"Login as guest": "Login as guest",
|
"Login as guest": "Login as guest",
|
||||||
"Return to app": "Return to app",
|
"Return to app": "Return to app",
|
||||||
"Failed to fetch avatar URL": "Failed to fetch avatar URL",
|
"Failed to fetch avatar URL": "Failed to fetch avatar URL",
|
||||||
|
|
Loading…
Reference in a new issue