From e2c473b366e9494d4096a16a52f96df91f9dcc3d Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 6 Jul 2016 15:22:06 +0100 Subject: [PATCH 1/4] Error on registration if email taken Use the new register-specific request token endpoint (https://github.com/matrix-org/matrix-js-sdk/pull/147) and catch the error that it gives if the email is already in use. Also add initial values to the registration form so we can reload it after the error without all the values disappearing, and split out the guest username parameter which was previously called defaultUsername. --- src/Signup.js | 5 +++- src/SignupStages.js | 6 ++--- .../structures/login/Registration.js | 14 ++++++++--- .../views/login/RegistrationForm.js | 24 +++++++++---------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/Signup.js b/src/Signup.js index 4518955d95..5aadd94701 100644 --- a/src/Signup.js +++ b/src/Signup.js @@ -152,7 +152,10 @@ class Register extends Signup { console.log("Active flow => %s", JSON.stringify(flow)); var flowStage = self.firstUncompletedStage(flow); if (flowStage != self.activeStage) { - return self.startStage(flowStage); + return self.startStage(flowStage).catch(function(err) { + self.setStep('START'); + throw err; + }); } } } diff --git a/src/SignupStages.js b/src/SignupStages.js index 1c5c48ddd6..2b0d163a08 100644 --- a/src/SignupStages.js +++ b/src/SignupStages.js @@ -170,7 +170,7 @@ class EmailIdentityStage extends Stage { encodeURIComponent(this.signupInstance.getServerData().session); var self = this; - return this.client.requestEmailToken( + return this.client.requestRegisterEmailToken( this.signupInstance.email, this.clientSecret, 1, // TODO: Multiple send attempts? @@ -186,8 +186,8 @@ class EmailIdentityStage extends Stage { var e = { isFatal: true }; - if (error.errcode == 'THREEPID_IN_USE') { - e.message = "Email in use"; + if (error.errcode == 'M_THREEPID_IN_USE') { + e.message = "This email address is already registered"; } else { e.message = 'Unable to contact the given identity server'; } diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index 2f15a3b5df..4615031760 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -54,6 +54,9 @@ module.exports = React.createClass({ return { busy: false, errorText: null, + formVals: { + email: this.props.email, + }, }; }, @@ -108,7 +111,8 @@ module.exports = React.createClass({ var self = this; this.setState({ errorText: "", - busy: true + busy: true, + formVals: formVals, }); if (formVals.username !== this.props.username) { @@ -228,11 +232,15 @@ module.exports = React.createClass({ break; // NOP case "Register.START": case "Register.STEP_m.login.dummy": + // NB. Our 'username' prop is specifically for upgrading + // a guest account registerStep = ( diff --git a/src/components/views/login/RegistrationForm.js b/src/components/views/login/RegistrationForm.js index a172d77bb4..17827d5b46 100644 --- a/src/components/views/login/RegistrationForm.js +++ b/src/components/views/login/RegistrationForm.js @@ -37,6 +37,8 @@ module.exports = React.createClass({ propTypes: { defaultEmail: React.PropTypes.string, defaultUsername: React.PropTypes.string, + defaultPassword: React.PropTypes.string, + guestUsername: React.PropTypes.string, showEmail: React.PropTypes.bool, minPasswordLength: React.PropTypes.number, onError: React.PropTypes.func, @@ -55,10 +57,6 @@ module.exports = React.createClass({ getInitialState: function() { return { - email: this.props.defaultEmail, - username: null, - password: null, - passwordConfirm: null, fieldValid: {} }; }, @@ -103,7 +101,7 @@ module.exports = React.createClass({ _doSubmit: function() { var promise = this.props.onRegisterClick({ - username: this.refs.username.value.trim() || this.props.defaultUsername, + username: this.refs.username.value.trim() || this.props.guestUsername, password: this.refs.password.value.trim(), email: this.refs.email.value.trim() }); @@ -144,7 +142,7 @@ module.exports = React.createClass({ break; case FIELD_USERNAME: // XXX: SPEC-1 - var username = this.refs.username.value.trim() || this.props.defaultUsername; + var username = this.refs.username.value.trim() || this.props.guestUsername; if (encodeURIComponent(username) != username) { this.markFieldValid( field_id, @@ -225,7 +223,7 @@ module.exports = React.createClass({ emailSection = ( ); @@ -237,8 +235,8 @@ module.exports = React.createClass({ } var placeholderUserName = "User name"; - if (this.props.defaultUsername) { - placeholderUserName += " (default: " + this.props.defaultUsername + ")" + if (this.props.guestUsername) { + placeholderUserName += " (default: " + this.props.guestUsername + ")" } return ( @@ -247,23 +245,23 @@ module.exports = React.createClass({ {emailSection}

- { this.props.defaultUsername ? + { this.props.guestUsername ?
Setting a user name will create a fresh account
: null } + placeholder="Password" defaultValue={this.props.defaultPassword} />
+ defaultValue={this.props.defaultPassword} />
{registerButton} From 5c879d786e1e8b51ea24b6f8f3a6278d79717800 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 7 Jul 2016 11:23:08 +0100 Subject: [PATCH 2/4] Doc the default params / guestUsername props --- src/components/views/login/RegistrationForm.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/views/login/RegistrationForm.js b/src/components/views/login/RegistrationForm.js index 17827d5b46..ad3526c598 100644 --- a/src/components/views/login/RegistrationForm.js +++ b/src/components/views/login/RegistrationForm.js @@ -35,10 +35,16 @@ module.exports = React.createClass({ displayName: 'RegistrationForm', propTypes: { + // Values pre-filled in the input boxes when the component loads defaultEmail: React.PropTypes.string, defaultUsername: React.PropTypes.string, defaultPassword: React.PropTypes.string, + + // A username that will be used if no username is enetered. + // Specifying this param will also warn the user that enetering + // a different username will cause a fresh account to be generated. guestUsername: React.PropTypes.string, + showEmail: React.PropTypes.bool, minPasswordLength: React.PropTypes.number, onError: React.PropTypes.func, From a6b04c462e26ff32d58dfdfdfc9b103636afe1fa Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 7 Jul 2016 11:26:35 +0100 Subject: [PATCH 3/4] Comment how we're remembering form vals --- src/components/structures/login/Registration.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index 4615031760..5126965407 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -54,6 +54,13 @@ module.exports = React.createClass({ return { busy: false, errorText: null, + // We remember the values entered by the user because + // the registration form will be unmounted during the + // course of registration, but if there's an error we + // want to bring back the registration form with the + // values the user enetered still in it. We can keep + // them in this component's state since this component + // persist for the duration of the registration process. formVals: { email: this.props.email, }, From 345ed04ba9e362d56600776b9bc4595a2ffe2354 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 7 Jul 2016 13:03:27 +0100 Subject: [PATCH 4/4] Less enetering --- src/components/structures/login/Registration.js | 2 +- src/components/views/login/RegistrationForm.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index 5126965407..423d62933f 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -58,7 +58,7 @@ module.exports = React.createClass({ // the registration form will be unmounted during the // course of registration, but if there's an error we // want to bring back the registration form with the - // values the user enetered still in it. We can keep + // values the user entered still in it. We can keep // them in this component's state since this component // persist for the duration of the registration process. formVals: { diff --git a/src/components/views/login/RegistrationForm.js b/src/components/views/login/RegistrationForm.js index ad3526c598..39c1acc625 100644 --- a/src/components/views/login/RegistrationForm.js +++ b/src/components/views/login/RegistrationForm.js @@ -40,8 +40,8 @@ module.exports = React.createClass({ defaultUsername: React.PropTypes.string, defaultPassword: React.PropTypes.string, - // A username that will be used if no username is enetered. - // Specifying this param will also warn the user that enetering + // A username that will be used if no username is entered. + // Specifying this param will also warn the user that entering // a different username will cause a fresh account to be generated. guestUsername: React.PropTypes.string,