Permalink
Browse files

[api] jitsu users confirm command can now accept invite code.

  • Loading branch information...
1 parent ea5f218 commit ebeb8605a66a4261499dec9838d0095c8b66b78b @Marak Marak committed Nov 18, 2011
Showing with 26 additions and 11 deletions.
  1. +26 −11 lib/jitsu/commands/users.js
View
37 lib/jitsu/commands/users.js
@@ -155,19 +155,17 @@ users.available.usage = [
// Attempts to confirm the Nodejitsu user account with the specified `username`.
// Prompts the user for additional `inviteCode` information.
//
-users.confirm = function (username, callback) {
- if (!callback) {
- callback = username;
- return callback(new Error('username is required'), true);
- }
-
- jitsu.prompt.get(['Invite code'], function (err, result) {
+users.confirm = function (username, inviteCode, callback) {
+
+
+ var confirmUserHelper = function(username, inviteCode, callback) {
+ winston.info('Confirming user ' + username.magenta);
+
var user = {
username: username,
- inviteCode: result['invite code']
+ inviteCode: inviteCode
};
- winston.info('Confirming user ' + username.magenta);
jitsu.users.confirm(user, function (err, response) {
if (err) {
return callback(err);
@@ -177,7 +175,9 @@ users.confirm = function (username, callback) {
winston.error(response.error);
return callback(response.error);
}
- else if (!response.hasPassword) {
+
+ winston.info('Great success! ' + username.magenta + ' is now confirmed.');
+ if (!response.hasPassword) {
(function getNewPass() {
winston.help('Now that your account is confirmed, you will need to set a password.');
@@ -204,8 +204,23 @@ users.confirm = function (username, callback) {
else {
winston.info('User ' + username.magenta + ' confirmed');
}
-
});
+
+ }
+
+ if (!callback) {
+ callback = username;
+ return callback(new Error('username is required'), true);
+ }
+ else if (typeof callback === 'function') {
+ // They are providing an inviteCode so lets reset the password
+ return confirmUserHelper(username, inviteCode, callback);
+ }
+
+ callback = inviteCode;
+
+ jitsu.prompt.get(['Invite code'], function (err, result) {
+ confirmUserHelper(username, result['Invite code'], callback);
});
};

0 comments on commit ebeb860

Please sign in to comment.