From ba50ef8445de87670148428e4c3df3e5e209a6ca Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 31 Jan 2019 16:37:37 -0600 Subject: [PATCH 1/2] Clarify required auth stages --- src/components/views/auth/RegistrationForm.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/views/auth/RegistrationForm.js b/src/components/views/auth/RegistrationForm.js index 76b4cdb621..f18d2c2a49 100644 --- a/src/components/views/auth/RegistrationForm.js +++ b/src/components/views/auth/RegistrationForm.js @@ -270,11 +270,15 @@ module.exports = React.createClass({ this.validateField(FIELD_USERNAME, ev.type); }, + /** + * A step is required if all flows include that step. + * + * @param {string} step A stage name to check + * @returns {boolean} Whether it is required + */ _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); + return this.props.flows.every((flow) => { + return flow.stages.includes(step); }); }, From 4ed13e897aa6c6d5cf4784c20f913fa7cf60a789 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 31 Jan 2019 18:07:40 -0600 Subject: [PATCH 2/2] Hide registration fields that aren't used by any flow --- src/components/views/auth/RegistrationForm.js | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/components/views/auth/RegistrationForm.js b/src/components/views/auth/RegistrationForm.js index f18d2c2a49..acde4d03fe 100644 --- a/src/components/views/auth/RegistrationForm.js +++ b/src/components/views/auth/RegistrationForm.js @@ -282,6 +282,18 @@ module.exports = React.createClass({ }); }, + /** + * A step is used if any flows include that step. + * + * @param {string} step A stage name to check + * @returns {boolean} Whether it is used + */ + _authStepIsUsed(step) { + return this.props.flows.some((flow) => { + return flow.stages.includes(step); + }); + }, + render: function() { let yourMatrixAccountText = _t('Create your account'); try { @@ -302,24 +314,28 @@ module.exports = React.createClass({ ; } - const emailPlaceholder = this._authStepIsRequired('m.login.email.identity') ? - _t("Email") : - _t("Email (optional)"); + let emailSection; + if (this._authStepIsUsed('m.login.email.identity')) { + const emailPlaceholder = this._authStepIsRequired('m.login.email.identity') ? + _t("Email") : + _t("Email (optional)"); - const emailSection = ( -
- -
- ); + emailSection = ( +
+ +
+ ); + } + const threePidLogin = !SdkConfig.get().disable_3pid_login; const CountryDropdown = sdk.getComponent('views.auth.CountryDropdown'); let phoneSection; - if (!SdkConfig.get().disable_3pid_login) { + if (threePidLogin && this._authStepIsUsed('m.login.msisdn')) { const phonePlaceholder = this._authStepIsRequired('m.login.msisdn') ? _t("Phone") : _t("Phone (optional)");