Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a sign up command and fixed a visual bug #57

Merged
merged 2 commits into from Jul 2, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions lib/jitsu/api/users.js
Expand Up @@ -80,3 +80,35 @@ Users.prototype.forgot = function (username, callback) {
callback(null, result);
});
};

//
// ### function isAvailable (username, callback)
// #### @user {String} the username to check if its available
// #### @callback {function} Continuation to pass control to when complete
// check if the username is available
//
Users.prototype.isAvailable = function (username, callback) {
this.request('GET', ['users', username, 'available'], null, callback, function (res, result) {
callback(null, result);
});
};

//
// ### function submit (username, email, password, callback)
// #### @user {String} the username to create
// #### @email {String} the user's email
// #### @password {String} the user's password
// #### @callback {function} Continuation to pass control to when complete
// try and create a username
//
Users.prototype.submit = function (username, email, password, callback) {
var options = {
username: username,
email: email,
password: password
};

this.request('POST', ['users', username], options, callback, function (res, result) {
callback(null, result);
});
};
64 changes: 62 additions & 2 deletions lib/jitsu/commands/users.js
Expand Up @@ -171,7 +171,7 @@ users.forgot = function (username, callback) {
return callback(new Error('Username is required'), true);
}

winston.info('Request password reset for :' + username.magenta);
winston.info('Request password reset for: ' + username.magenta);
jitsu.users.forgot(username, function (err, result) {
if (err) {
return callback(err);
Expand All @@ -186,4 +186,64 @@ users.forgot.usage = [
'Sends the password reset email to the user with the specified `username`.',
'',
'jitsu users forgot <username>'
];
];

//
// ### function signup (callback)
// #### @callback {function} Continuation to pass control to when complete.
// Creates an account with nodejitsu
//
users.signup = function (callback) {
var username, email, password;
getUsername();
function getUsername() {
jitsu.prompt.get('username', function (err, result) {
jitsu.users.isAvailable(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();
}
});
}

function getPassword() {
jitsu.prompt.get(['password', {name:'confirm password', hidden: true}], function (err, result) {
if (result['password'] === result['confirm password'] && result['password'] != "") {
password = result['password'];
jitsu.users.submit(username, email, password, function(err) {
callback(err);
});
}
else {
winston.error('The entered passwords do not match');
getPassword();
}
});
}
}

users.signup.usage = [
'Creates a username with nodejitsu',
'',
'jitsu users signup'
];