From 7aa4d505604e3ce96968d533a727a5e8696ef347 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 16 Jul 2015 14:08:52 +0100 Subject: [PATCH 1/2] Handle registration errors. --- skins/base/views/templates/Register.js | 9 +++++++ src/controllers/templates/Register.js | 37 ++++++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/skins/base/views/templates/Register.js b/skins/base/views/templates/Register.js index 2a61fa2e94..13b9b2a1f1 100644 --- a/skins/base/views/templates/Register.js +++ b/skins/base/views/templates/Register.js @@ -104,6 +104,15 @@ module.exports = React.createClass({ case this.FieldErrors.PasswordMismatch: strings.push("Passwords don't match"); break; + case this.FieldErrors.Missing: + strings.push("Missing "+keys[i]); + break; + case this.FieldErrors.TooShort: + strings.push(keys[i]+" is too short"); + break; + case this.FieldErrors.InUse: + strings.push(keys[i]+" is already taken"); + break; } } var errtxt = strings.join(', '); diff --git a/src/controllers/templates/Register.js b/src/controllers/templates/Register.js index 4ad66d9f2b..2ff75e0c6c 100644 --- a/src/controllers/templates/Register.js +++ b/src/controllers/templates/Register.js @@ -27,7 +27,9 @@ var ComponentBroker = require("../../ComponentBroker"); module.exports = { FieldErrors: { PasswordMismatch: 'PasswordMismatch', - PasswordLength: 'PasswordLength' + TooShort: 'TooShort', + Missing: 'Missing', + InUse: 'InUse' }, getInitialState: function() { @@ -166,10 +168,18 @@ module.exports = { if (formVals.password != formVals.confirmPassword) { badFields.confirmPassword = this.FieldErrors.PasswordMismatch; } - if (formVals.password.length < 6) { - badFields.password = this.FieldErrors.PasswordLength; + if (formVals.password == '') { + badFields.password = this.FieldErrors.Missing; + } else if (formVals.password.length < 6) { + badFields.password = this.FieldErrors.Length; + } + if (formVals.username == '') { + badFields.username = this.FieldErrors.Missing; + } + if (Object.keys(badFields).length > 0) { + this.onBadFields(badFields); + return; } - this.onBadFields(badFields); MatrixClientPeg.replaceUsingUrls( this.getHsUrl(), @@ -308,15 +318,20 @@ module.exports = { }); self.startStage(flow.stages[flowStage]); } else { - var errorText = "Unable to contact the given Home Server"; - if (error.httpStatus == 401) { - errorText = "Authorisation failed!"; - } self.setStep("initial"); - self.setState({ + var newState = { busy: false, - errorText: errorText - }); + errorText: "Unable to contact the given Home Server" + }; + if (error.name == 'M_USER_IN_USE') { + delete newState.errorText; + self.onBadFields({ + username: self.FieldErrors.InUse + }); + } else if (error.httpStatus == 401) { + newState.errorText = "Authorisation failed!"; + } + self.setState(newState); } }); }, From a6df6ca29b135e266612fa014ba7c08e728176cf Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 16 Jul 2015 14:19:13 +0100 Subject: [PATCH 2/2] Don't forget form values on error --- skins/base/views/templates/Register.js | 8 ++++---- src/controllers/templates/Register.js | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/skins/base/views/templates/Register.js b/skins/base/views/templates/Register.js index 13b9b2a1f1..94f3b96971 100644 --- a/skins/base/views/templates/Register.js +++ b/skins/base/views/templates/Register.js @@ -53,10 +53,10 @@ module.exports = React.createClass({ return (
- Email:
- Username:
- Password:
- Confirm Password:
+ Email:
+ Username:
+ Password:
+ Confirm Password:
diff --git a/src/controllers/templates/Register.js b/src/controllers/templates/Register.js index 2ff75e0c6c..664b36b307 100644 --- a/src/controllers/templates/Register.js +++ b/src/controllers/templates/Register.js @@ -42,6 +42,12 @@ module.exports = { }, componentWillMount: function() { + this.savedParams = { + email: '', + username: '', + password: '', + confirmPassword: '' + }; this.readNewProps(); }, @@ -163,6 +169,7 @@ module.exports = { ev.preventDefault(); var formVals = this.getRegFormVals(); + this.savedParams = formVals; var badFields = {}; if (formVals.password != formVals.confirmPassword) {