From 7aa4d505604e3ce96968d533a727a5e8696ef347 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 16 Jul 2015 14:08:52 +0100 Subject: [PATCH] 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 2a61fa2e..13b9b2a1 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 4ad66d9f..2ff75e0c 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); } }); },