From 80b8cbb4730052a8ab8ce5bd442c24c924671ab0 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 27 Nov 2017 16:40:19 +0000 Subject: [PATCH 1/3] Ignore unrecognised login flows Update the Login component so that if it sees an unrecognised login flow, it just ignores it and uses another one, so that riot can still be used with homeservers supporting custom login types. --- src/components/structures/login/Login.js | 114 +++++++++++++++-------- src/i18n/strings/en_EN.json | 2 +- 2 files changed, 77 insertions(+), 39 deletions(-) diff --git a/src/components/structures/login/Login.js b/src/components/structures/login/Login.js index 8ee6eafad4..2e08c05853 100644 --- a/src/components/structures/login/Login.js +++ b/src/components/structures/login/Login.js @@ -76,6 +76,14 @@ module.exports = React.createClass({ componentWillMount: function() { 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(); }, @@ -217,13 +225,29 @@ module.exports = React.createClass({ loginIncorrect: false, }); - loginLogic.getFlows().then(function(flows) { - // old behaviour was to always use the first flow without presenting - // options. This works in most cases (we don't have a UI for multiple - // logins so let's skip that for now). - loginLogic.chooseFlow(0); - self.setState({ - currentFlow: self._getCurrentFlowStep(), + loginLogic.getFlows().then((flows) => { + // look for a flow where we understand all of the steps. + for (let i = 0; i < flows.length; i++ ) { + if (!this._isSupportedFlow(flows[i])) { + continue; + } + + // 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) { self.setState({ @@ -237,6 +261,16 @@ module.exports = React.createClass({ }).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() { return this._loginLogic ? this._loginLogic.getCurrentFlowStep() : null; }, @@ -276,38 +310,42 @@ module.exports = React.createClass({ }, componentForStep: function(step) { - switch (step) { - case 'm.login.password': - const PasswordLogin = sdk.getComponent('login.PasswordLogin'); - return ( - - ); - case 'm.login.cas': - const CasLogin = sdk.getComponent('login.CasLogin'); - return ( - - ); - default: - if (!step) { - return; - } - return ( -
- { _t('Sorry, this homeserver is using a login which is not recognised ') }({ step }) -
- ); + if (!step) { + return null; } + + const stepRenderer = this._stepRendererMap[step]; + + if (stepRenderer) { + return stepRenderer(); + } + + return null; + }, + + _renderPasswordStep: function() { + const PasswordLogin = sdk.getComponent('login.PasswordLogin'); + return ( + + ); + }, + + _renderCasStep: function() { + const CasLogin = sdk.getComponent('login.CasLogin'); + return ( + + ); }, _onLanguageChange: function(newLang) { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 4052d098c1..efb174c445 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -862,7 +862,7 @@ "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 enable unsafe scripts.": "Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or enable unsafe scripts.", "Can't connect to homeserver - please check your connectivity, ensure your homeserver's SSL certificate is trusted, and that a browser extension is not blocking requests.": "Can't connect to homeserver - please check your connectivity, ensure your homeserver's SSL certificate 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", "Return to app": "Return to app", "Failed to fetch avatar URL": "Failed to fetch avatar URL", From 36e663131b4a3fb69a496e84329e12ec4085f30c Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 28 Nov 2017 10:25:04 +0000 Subject: [PATCH 2/3] Prepare changelog for v0.11.2 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c0ea57a57..ef6d180616 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +Changes in [0.11.2](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v0.11.2) (2017-11-28) +===================================================================================================== +[Full Changelog](https://github.com/matrix-org/matrix-react-sdk/compare/v0.11.1...v0.11.2) + + * Ignore unrecognised login flows + [\#1633](https://github.com/matrix-org/matrix-react-sdk/pull/1633) + Changes in [0.11.1](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v0.11.1) (2017-11-17) ===================================================================================================== [Full Changelog](https://github.com/matrix-org/matrix-react-sdk/compare/v0.11.0...v0.11.1) From a088e559d11923a44a75b18ef0c9858fedaef5a1 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 28 Nov 2017 10:25:04 +0000 Subject: [PATCH 3/3] v0.11.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2970beb6b3..b443b4c72a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-react-sdk", - "version": "0.11.1", + "version": "0.11.2", "description": "SDK for matrix.org using React", "author": "matrix.org", "repository": {