From dc14a4214851337bd8e809edd11a7eb1f0dff9f0 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 4 Sep 2018 18:26:09 +0100 Subject: [PATCH 1/3] Correctly mark email as optional Look at the flows to see if there is one we can complete without an email address. Mark the email address as optional iff there is. --- .../structures/login/Registration.js | 22 +++++++++++++++++-- .../views/login/RegistrationForm.js | 19 +++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index 11312183118..257818b95cf 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -93,6 +93,7 @@ module.exports = React.createClass({ doingUIAuth: Boolean(this.props.sessionId), hsUrl: this.props.customHsUrl, isUrl: this.props.customIsUrl, + flows: null, }; }, @@ -145,11 +146,27 @@ module.exports = React.createClass({ }); }, - _replaceClient: function() { + _replaceClient: async function() { this._matrixClient = Matrix.createClient({ baseUrl: this.state.hsUrl, idBaseUrl: this.state.isUrl, }); + try { + const result = await this._makeRegisterRequest({}); + // This should never succeed since we specified an empty + // auth object. + console.log("Expecting 401 from register request but got success!"); + } catch (e) { + if (e.httpStatus === 401) { + this.setState({ + flows: e.data.flows, + }); + } else { + this.setState({ + errorText: _t("Unable to query for supported registration methods"), + }); + } + } }, onFormSubmit: function(formVals) { @@ -378,7 +395,7 @@ module.exports = React.createClass({ poll={true} /> ); - } else if (this.state.busy || this.state.teamServerBusy) { + } else if (this.state.busy || this.state.teamServerBusy || !this.state.flows) { registerBody = ; } else { let serverConfigSection; @@ -408,6 +425,7 @@ module.exports = React.createClass({ onError={this.onFormValidationFailed} onRegisterClick={this.onFormSubmit} onTeamSelected={this.onTeamSelected} + flows={this.state.flows} /> { serverConfigSection } diff --git a/src/components/views/login/RegistrationForm.js b/src/components/views/login/RegistrationForm.js index fff808cf226..56a2bcfee47 100644 --- a/src/components/views/login/RegistrationForm.js +++ b/src/components/views/login/RegistrationForm.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 Vector Creations Ltd +Copyright 2018 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -49,7 +50,7 @@ module.exports = React.createClass({ teamsConfig: PropTypes.shape({ // Email address to request new teams supportEmail: PropTypes.string, - teams: PropTypes.arrayOf(React.PropTypes.shape({ + teams: PropTypes.arrayOf(PropTypes.shape({ // The displayed name of the team "name": PropTypes.string, // The domain of team email addresses @@ -60,6 +61,7 @@ module.exports = React.createClass({ minPasswordLength: PropTypes.number, onError: PropTypes.func, onRegisterClick: PropTypes.func.isRequired, // onRegisterClick(Object) => ?Promise + flows: PropTypes.arrayOf(PropTypes.object), }, getDefaultProps: function() { @@ -273,12 +275,18 @@ module.exports = React.createClass({ }); }, + _authStepIsRequired(step) { + // A step is required if no flow exists which does not include that step + // (Notwithstanding setups like either email or msisdn being required) + return !this.props.flows.some((flow) => { + return !flow.stages.includes(step); + }); + }, + render: function() { const self = this; - const theme = SettingsStore.getValue("theme"); - // FIXME: remove hardcoded Status team tweaks at some point - const emailPlaceholder = theme === 'status' ? _t("Email address") : _t("Email address (optional)"); + const emailPlaceholder = this._authStepIsRequired('m.login.email.identity') ? _t("Email address") : _t("Email address (optional)"); const emailSection = (
@@ -315,6 +323,7 @@ module.exports = React.createClass({ const CountryDropdown = sdk.getComponent('views.login.CountryDropdown'); let phoneSection; if (!SdkConfig.get().disable_3pid_login) { + const phonePlaceholder = this._authStepIsRequired('m.login.msisdn') ? _t("Mobile phone number") : _t("Mobile phone number (optional)"); phoneSection = (
Date: Tue, 4 Sep 2018 18:50:18 +0100 Subject: [PATCH 2/3] Fix tests --- src/components/views/login/RegistrationForm.js | 2 +- test/components/views/login/RegistrationForm-test.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/views/login/RegistrationForm.js b/src/components/views/login/RegistrationForm.js index 56a2bcfee47..1a365277c14 100644 --- a/src/components/views/login/RegistrationForm.js +++ b/src/components/views/login/RegistrationForm.js @@ -61,7 +61,7 @@ module.exports = React.createClass({ minPasswordLength: PropTypes.number, onError: PropTypes.func, onRegisterClick: PropTypes.func.isRequired, // onRegisterClick(Object) => ?Promise - flows: PropTypes.arrayOf(PropTypes.object), + flows: PropTypes.arrayOf(PropTypes.object).isRequired, }, getDefaultProps: function() { diff --git a/test/components/views/login/RegistrationForm-test.js b/test/components/views/login/RegistrationForm-test.js index 81db5b487b0..14a5d036b41 100644 --- a/test/components/views/login/RegistrationForm-test.js +++ b/test/components/views/login/RegistrationForm-test.js @@ -37,6 +37,11 @@ function doInputEmail(inputEmail, onTeamSelected) { , ); From 775d9950521aa35fbb838ea737c13353bb8c6b38 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 4 Sep 2018 18:51:24 +0100 Subject: [PATCH 3/3] Lint --- src/components/structures/login/Registration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index 257818b95cf..f3744b72359 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -152,7 +152,7 @@ module.exports = React.createClass({ idBaseUrl: this.state.isUrl, }); try { - const result = await this._makeRegisterRequest({}); + await this._makeRegisterRequest({}); // This should never succeed since we specified an empty // auth object. console.log("Expecting 401 from register request but got success!");