Skip to content

Commit 7aa4d50

Browse files
committed
Handle registration errors.
1 parent df790c1 commit 7aa4d50

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

‎skins/base/views/templates/Register.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ module.exports = React.createClass({
104104
case this.FieldErrors.PasswordMismatch:
105105
strings.push("Passwords don't match");
106106
break;
107+
case this.FieldErrors.Missing:
108+
strings.push("Missing "+keys[i]);
109+
break;
110+
case this.FieldErrors.TooShort:
111+
strings.push(keys[i]+" is too short");
112+
break;
113+
case this.FieldErrors.InUse:
114+
strings.push(keys[i]+" is already taken");
115+
break;
107116
}
108117
}
109118
var errtxt = strings.join(', ');

‎src/controllers/templates/Register.js‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ var ComponentBroker = require("../../ComponentBroker");
2727
module.exports = {
2828
FieldErrors: {
2929
PasswordMismatch: 'PasswordMismatch',
30-
PasswordLength: 'PasswordLength'
30+
TooShort: 'TooShort',
31+
Missing: 'Missing',
32+
InUse: 'InUse'
3133
},
3234

3335
getInitialState: function() {
@@ -166,10 +168,18 @@ module.exports = {
166168
if (formVals.password != formVals.confirmPassword) {
167169
badFields.confirmPassword = this.FieldErrors.PasswordMismatch;
168170
}
169-
if (formVals.password.length < 6) {
170-
badFields.password = this.FieldErrors.PasswordLength;
171+
if (formVals.password == '') {
172+
badFields.password = this.FieldErrors.Missing;
173+
} else if (formVals.password.length < 6) {
174+
badFields.password = this.FieldErrors.Length;
175+
}
176+
if (formVals.username == '') {
177+
badFields.username = this.FieldErrors.Missing;
178+
}
179+
if (Object.keys(badFields).length > 0) {
180+
this.onBadFields(badFields);
181+
return;
171182
}
172-
this.onBadFields(badFields);
173183

174184
MatrixClientPeg.replaceUsingUrls(
175185
this.getHsUrl(),
@@ -308,15 +318,20 @@ module.exports = {
308318
});
309319
self.startStage(flow.stages[flowStage]);
310320
} else {
311-
var errorText = "Unable to contact the given Home Server";
312-
if (error.httpStatus == 401) {
313-
errorText = "Authorisation failed!";
314-
}
315321
self.setStep("initial");
316-
self.setState({
322+
var newState = {
317323
busy: false,
318-
errorText: errorText
319-
});
324+
errorText: "Unable to contact the given Home Server"
325+
};
326+
if (error.name == 'M_USER_IN_USE') {
327+
delete newState.errorText;
328+
self.onBadFields({
329+
username: self.FieldErrors.InUse
330+
});
331+
} else if (error.httpStatus == 401) {
332+
newState.errorText = "Authorisation failed!";
333+
}
334+
self.setState(newState);
320335
}
321336
});
322337
},

0 commit comments

Comments
 (0)