@@ -27,7 +27,9 @@ var ComponentBroker = require("../../ComponentBroker");
2727module . exports = {
2828 FieldErrors : {
2929 PasswordMismatch : 'PasswordMismatch' ,
30- PasswordLength : 'PasswordLength'
30+ TooShort : 'TooShort' ,
31+ Missing : 'Missing' ,
32+ InUse : 'InUse'
3133 } ,
3234
3335 getInitialState : function ( ) {
@@ -40,6 +42,12 @@ module.exports = {
4042 } ,
4143
4244 componentWillMount : function ( ) {
45+ this . savedParams = {
46+ email : '' ,
47+ username : '' ,
48+ password : '' ,
49+ confirmPassword : ''
50+ } ;
4351 this . readNewProps ( ) ;
4452 } ,
4553
@@ -161,15 +169,24 @@ module.exports = {
161169 ev . preventDefault ( ) ;
162170
163171 var formVals = this . getRegFormVals ( ) ;
172+ this . savedParams = formVals ;
164173
165174 var badFields = { } ;
166175 if ( formVals . password != formVals . confirmPassword ) {
167176 badFields . confirmPassword = this . FieldErrors . PasswordMismatch ;
168177 }
169- if ( formVals . password . length < 6 ) {
170- badFields . password = this . FieldErrors . PasswordLength ;
178+ if ( formVals . password == '' ) {
179+ badFields . password = this . FieldErrors . Missing ;
180+ } else if ( formVals . password . length < 6 ) {
181+ badFields . password = this . FieldErrors . Length ;
182+ }
183+ if ( formVals . username == '' ) {
184+ badFields . username = this . FieldErrors . Missing ;
185+ }
186+ if ( Object . keys ( badFields ) . length > 0 ) {
187+ this . onBadFields ( badFields ) ;
188+ return ;
171189 }
172- this . onBadFields ( badFields ) ;
173190
174191 MatrixClientPeg . replaceUsingUrls (
175192 this . getHsUrl ( ) ,
@@ -308,15 +325,20 @@ module.exports = {
308325 } ) ;
309326 self . startStage ( flow . stages [ flowStage ] ) ;
310327 } else {
311- var errorText = "Unable to contact the given Home Server" ;
312- if ( error . httpStatus == 401 ) {
313- errorText = "Authorisation failed!" ;
314- }
315328 self . setStep ( "initial" ) ;
316- self . setState ( {
329+ var newState = {
317330 busy : false ,
318- errorText : errorText
319- } ) ;
331+ errorText : "Unable to contact the given Home Server"
332+ } ;
333+ if ( error . name == 'M_USER_IN_USE' ) {
334+ delete newState . errorText ;
335+ self . onBadFields ( {
336+ username : self . FieldErrors . InUse
337+ } ) ;
338+ } else if ( error . httpStatus == 401 ) {
339+ newState . errorText = "Authorisation failed!" ;
340+ }
341+ self . setState ( newState ) ;
320342 }
321343 } ) ;
322344 } ,
0 commit comments