Skip to content
Browse files

[fix] Readd username in `jitsu signup` / `jitsu users create`. It is …

…now **optional**
  • Loading branch information...
1 parent 26954d5 commit 8f7ce83addbd9d93ab8686309e70e1e01ea85089 @indexzero indexzero committed Aug 10, 2011
Showing with 47 additions and 38 deletions.
  1. +47 −38 lib/jitsu/commands/users.js
View
85 lib/jitsu/commands/users.js
@@ -32,68 +32,77 @@ users.usage = [
// Attempts to create a Nodejitsu user account with the specified `username`.
// Prompts the user for additional `email` and `password` information.
//
-users.create = function (callback) {
- var username, email, password;
- getUsername();
- function getUsername() {
- jitsu.prompt.get('username', function (err, result) {
- jitsu.users.available(result.username, function (err,result1) {
- if (err) {
- callback(err);
- }
- else if (result1.available === false) {
- winston.error('Username was already taken');
- getUsername();
- }
- else {
- username = result.username;
- getEmail();
- }
- })
- });
- }
-
- function getEmail() {
- jitsu.prompt.get('email', function (err, result) {
- if (err) {
- callback(err);
- }
- else {
- email = result.email;
- getPassword();
- }
- });
+users.create = function (username, callback) {
+ var email, password;
+
+ if (!callback && typeof username === 'function') {
+ callback = username;
+ username = null;
}
-
+
function getPassword() {
- jitsu.prompt.get(['password', {name:'confirm password', hidden: true}], function (err, result) {
+ jitsu.prompt.get(['password', { name:'confirm password', hidden: true }], function (err, result) {
if (result['password'] === result['confirm password'] && result['password'] !== "") {
- password = result['password'];
- var options = {
+ password = result.password;
+ jitsu.users.create({
username: username,
email: email,
password: password
- };
- jitsu.users.create(options, callback);
+ }, callback);
}
else {
if (result['password'] === "") {
winston.error('You password must have characters in it');
} else {
winston.error('The entered passwords do not match');
}
+
getPassword();
}
});
}
+
+ function getEmail() {
+ jitsu.prompt.get('email', function (err, result) {
+ if (err) {
+ return callback(err);
+ }
+
+ email = result.email;
+ getPassword();
+ });
+ }
+
+ function getUsername() {
+ jitsu.prompt.get('username', function (err, result) {
+ jitsu.users.available(result.username, function (err, res) {
+ if (err) {
+ return callback(err);
+ }
+ else if (res.available === false) {
+ winston.error('Username was already taken');
+ return getUsername();
+ }
+
+ username = result.username;
+ getEmail();
+ })
+ });
+ }
+
+ return !username
+ ? getUsername()
+ : getEmail();
};
users.create.usage = [
'Creates a new user account with Nodejitsu. You will be',
'prompted to provide additional `email` and `password` information.',
'',
'jitsu users create',
- 'jitsu signup'
+ 'jitsu users create <username>',
+ 'jitsu signup',
+ 'jitsu signup <username>'
];
//

0 comments on commit 8f7ce83

Please sign in to comment.
Something went wrong with that request. Please try again.