Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 4a20185

Browse files
authored
Merge pull request #1633 from matrix-org/rav/handle_login_flows_better
Ignore unrecognised login flows
2 parents 394e450 + 80b8cbb commit 4a20185

File tree

2 files changed

+77
-39
lines changed

2 files changed

+77
-39
lines changed

src/components/structures/login/Login.js

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ module.exports = React.createClass({
7676

7777
componentWillMount: function() {
7878
this._unmounted = false;
79+
80+
// map from login step type to a function which will render a control
81+
// letting you do that login type
82+
this._stepRendererMap = {
83+
'm.login.password': this._renderPasswordStep,
84+
'm.login.cas': this._renderCasStep,
85+
};
86+
7987
this._initLoginLogic();
8088
},
8189

@@ -217,13 +225,29 @@ module.exports = React.createClass({
217225
loginIncorrect: false,
218226
});
219227

220-
loginLogic.getFlows().then(function(flows) {
221-
// old behaviour was to always use the first flow without presenting
222-
// options. This works in most cases (we don't have a UI for multiple
223-
// logins so let's skip that for now).
224-
loginLogic.chooseFlow(0);
225-
self.setState({
226-
currentFlow: self._getCurrentFlowStep(),
228+
loginLogic.getFlows().then((flows) => {
229+
// look for a flow where we understand all of the steps.
230+
for (let i = 0; i < flows.length; i++ ) {
231+
if (!this._isSupportedFlow(flows[i])) {
232+
continue;
233+
}
234+
235+
// we just pick the first flow where we support all the
236+
// steps. (we don't have a UI for multiple logins so let's skip
237+
// that for now).
238+
loginLogic.chooseFlow(i);
239+
this.setState({
240+
currentFlow: this._getCurrentFlowStep(),
241+
});
242+
return;
243+
}
244+
// we got to the end of the list without finding a suitable
245+
// flow.
246+
this.setState({
247+
errorText: _t(
248+
"This homeserver doesn't offer any login flows which are " +
249+
"supported by this client.",
250+
),
227251
});
228252
}, function(err) {
229253
self.setState({
@@ -237,6 +261,16 @@ module.exports = React.createClass({
237261
}).done();
238262
},
239263

264+
_isSupportedFlow: function(flow) {
265+
// technically the flow can have multiple steps, but no one does this
266+
// for login and loginLogic doesn't support it so we can ignore it.
267+
if (!this._stepRendererMap[flow.type]) {
268+
console.log("Skipping flow", flow, "due to unsupported login type", flow.type);
269+
return false;
270+
}
271+
return true;
272+
},
273+
240274
_getCurrentFlowStep: function() {
241275
return this._loginLogic ? this._loginLogic.getCurrentFlowStep() : null;
242276
},
@@ -276,38 +310,42 @@ module.exports = React.createClass({
276310
},
277311

278312
componentForStep: function(step) {
279-
switch (step) {
280-
case 'm.login.password':
281-
const PasswordLogin = sdk.getComponent('login.PasswordLogin');
282-
return (
283-
<PasswordLogin
284-
onSubmit={this.onPasswordLogin}
285-
initialUsername={this.state.username}
286-
initialPhoneCountry={this.state.phoneCountry}
287-
initialPhoneNumber={this.state.phoneNumber}
288-
onUsernameChanged={this.onUsernameChanged}
289-
onPhoneCountryChanged={this.onPhoneCountryChanged}
290-
onPhoneNumberChanged={this.onPhoneNumberChanged}
291-
onForgotPasswordClick={this.props.onForgotPasswordClick}
292-
loginIncorrect={this.state.loginIncorrect}
293-
hsUrl={this.state.enteredHomeserverUrl}
294-
/>
295-
);
296-
case 'm.login.cas':
297-
const CasLogin = sdk.getComponent('login.CasLogin');
298-
return (
299-
<CasLogin onSubmit={this.onCasLogin} />
300-
);
301-
default:
302-
if (!step) {
303-
return;
304-
}
305-
return (
306-
<div>
307-
{ _t('Sorry, this homeserver is using a login which is not recognised ') }({ step })
308-
</div>
309-
);
313+
if (!step) {
314+
return null;
315+
}
316+
317+
const stepRenderer = this._stepRendererMap[step];
318+
319+
if (stepRenderer) {
320+
return stepRenderer();
310321
}
322+
323+
return null;
324+
},
325+
326+
_renderPasswordStep: function() {
327+
const PasswordLogin = sdk.getComponent('login.PasswordLogin');
328+
return (
329+
<PasswordLogin
330+
onSubmit={this.onPasswordLogin}
331+
initialUsername={this.state.username}
332+
initialPhoneCountry={this.state.phoneCountry}
333+
initialPhoneNumber={this.state.phoneNumber}
334+
onUsernameChanged={this.onUsernameChanged}
335+
onPhoneCountryChanged={this.onPhoneCountryChanged}
336+
onPhoneNumberChanged={this.onPhoneNumberChanged}
337+
onForgotPasswordClick={this.props.onForgotPasswordClick}
338+
loginIncorrect={this.state.loginIncorrect}
339+
hsUrl={this.state.enteredHomeserverUrl}
340+
/>
341+
);
342+
},
343+
344+
_renderCasStep: function() {
345+
const CasLogin = sdk.getComponent('login.CasLogin');
346+
return (
347+
<CasLogin onSubmit={this.onCasLogin} />
348+
);
311349
},
312350

313351
_onLanguageChange: function(newLang) {

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@
862862
"Error: Problem communicating with the given homeserver.": "Error: Problem communicating with the given homeserver.",
863863
"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>.",
864864
"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.",
865-
"Sorry, this homeserver is using a login which is not recognised ": "Sorry, this homeserver is using a login which is not recognised ",
865+
"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.",
866866
"Login as guest": "Login as guest",
867867
"Return to app": "Return to app",
868868
"Failed to fetch avatar URL": "Failed to fetch avatar URL",

0 commit comments

Comments
 (0)