Skip to content

Commit 388e1a7

Browse files
committed
better error handling for register, also forces to enter email
1 parent d3e3d89 commit 388e1a7

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/commands/register.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs')
22
, Syncano = require('syncano')
3+
, validator = require('validator');
34
;
45

56
module.exports = function(FASTACK) {
@@ -24,10 +25,21 @@ module.exports = function(FASTACK) {
2425
}
2526
], function(answers) {
2627
var fastack = new Syncano({instance: 'fastack', apiKey: FASTACK.apiKey});
27-
fastack.user().add({
28-
username: answers.username,
29-
password: answers.password
30-
});
28+
var responses = { username: answers.username, email: answers.email, password: answers.password }
29+
30+
if( answers.email && validator.isEmail( answers.email ) ){
31+
fastack.user().add( responses ).then(function(){
32+
FASTACK.logger.log("Account created.");
33+
callback();
34+
}, function(err){
35+
FASTACK.logger.log("Error info: " + err);
36+
callback();
37+
});
38+
} else {
39+
FASTACK.logger.log("Not a valid e-mail address. Please try again.");
40+
callback();
41+
}
42+
3143
});
3244
}
3345
};

0 commit comments

Comments
 (0)