Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #63 from nicoreed/master

Signup command and login command
  • Loading branch information...
commit f7aee73fee8267202889376cf27805fed9fc63dd 2 parents 04816e5 + 0dc265e
Nico Reed authored
View
12 README.md
@@ -57,7 +57,15 @@ If it's your first time using `jitsu`, you will be prompted to login with an exi
jitsu <resource> <action> <param1> <param2> ...
**Common Commands:**
-
+
+ *To sign up for [Nodejitsu](http://nodejitsu.com)*
+
+ jitsu signup
+
+ *To log into [Nodejitsu](http://nodejitsu.com)*
+
+ jitsu login
+
*Deploys current path to [Nodejitsu](http://nodejitsu.com)*
jitsu deploy
@@ -127,4 +135,4 @@ If you need to have multiple configuration files, use --localconf or --jitsuconf
### Need more?
The documentation for `jitsu` and the [Nodejitsu](http://nodejitsu.com) APIs is open-source and a work in-progress. For more information checkout the [Nodejitsu Handbook](http://github.com/nodejitsu/handbook)
-#### (C) Copyright 2010, [Nodejitsu](http://nodejitsu.com) Inc.
+#### (C) Copyright 2010, [Nodejitsu](http://nodejitsu.com) Inc.
View
11 lib/jitsu.js
@@ -50,7 +50,9 @@ jitsu.commands.alias('create', { resource: 'apps', command: 'create' });
jitsu.commands.alias('deploy', { resource: 'apps', command: 'deploy' });
jitsu.commands.alias('list', { resource: 'apps', command: 'list' });
jitsu.commands.alias('conf', { resource: 'config', command: 'list' });
+jitsu.commands.alias('login', { resource: 'users', command: 'login' });
jitsu.commands.alias('logout', { resource: 'users', command: 'logout' });
+jitsu.commands.alias('signup', { resource: 'users', command: 'create' });
var eyes = require('eyes'),
winston = require('winston'),
@@ -194,7 +196,16 @@ jitsu.auth = function (callback) {
//
jitsu.setupUser = function (callback) {
winston.warn('No user has been setup on this machine');
+ jitsu.setupUserNoWarn(callback);
+};
+//
+// ### function setupUserNoWarn (callback)
+// #### @callback {function} Continuation to pass control to when complete.
+// Prompts the user for their username / password combo, then sets up the jitsu CLI,
+// and saves the resulting configuration to disk without a warning
+//
+jitsu.setupUserNoWarn = function(callback) {
//
// Attempt to get the password three times.
//
View
31 lib/jitsu/api/users.js
@@ -81,34 +81,3 @@ Users.prototype.forgot = function (username, callback) {
});
};
-//
-// ### 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);
- });
-};
View
2  lib/jitsu/commands.js
@@ -136,4 +136,4 @@ commands.alias = function (target, source) {
if (requireAuth.indexOf(source.resource) !== -1) {
requireAuth.push(target);
}
-};
+};
View
10 lib/jitsu/commands/help.js
@@ -30,6 +30,16 @@ help.usage = [
'Common Commands:'.cyan.bold.underline,
'',
+ 'To sign up for Nodejitsu'.cyan,
+ '',
+ ' jitsu signup',
+ '',
+
+ 'To log into Nodejitsu'.cyan,
+ '',
+ ' jitsu login',
+ '',
+
'Deploys current path to Nodejitsu'.cyan,
'',
' jitsu deploy',
View
136 lib/jitsu/commands/users.js
@@ -14,7 +14,7 @@ users.usage = [
'`jitsu users *` commands allow you to work with new',
'or existing Nodejitsu user accounts',
'',
- 'jitsu users create <username>',
+ 'jitsu users create',
'jitsu users available <username>',
'jitsu users confirm <username>',
'jitsu users forgot <username>',
@@ -31,31 +31,68 @@ 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 (username, callback) {
- if (!callback) {
- callback = username;
- return callback(new Error('username is required'), true);
+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();
+ }
+ })
+ });
}
-
- jitsu.prompt.get(['email', 'password'], function (err, result) {
- var user = {
- email: result.email,
- password: result.password,
- username: username
- };
- winston.info('Creating user ' + username.magenta);
- jitsu.users.create(user, function (err) {
- return err ? callback(err) : callback();
+ 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'];
+ var options = {
+ username: username,
+ email: email,
+ password: password
+ };
+ jitsu.users.create(options, callback);
+ }
+ else {
+ if (result['password'] === "") {
+ winston.error('You password must have characters in it');
+ } else {
+ winston.error('The entered passwords do not match');
+ }
+ getPassword();
+ }
+ });
+ }
};
users.create.usage = [
'Creates a new user account with Nodejitsu. You will be',
'prompted to provide additional `email` and `password` information.',
'',
- 'jitsu users create <username>'
+ 'jitsu users create',
+ 'jitsu signup'
];
//
@@ -123,7 +160,7 @@ users.confirm = function (username, callback) {
callback();
});
- });
+ });
};
users.confirm.usage = [
@@ -188,62 +225,13 @@ users.forgot.usage = [
'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.login = function(callback) {
+ jitsu.setupUserNoWarn(callback);
}
-users.signup.usage = [
- 'Creates a username with nodejitsu',
+users.login.usage = [
+ 'Allows the user to login',
'',
- 'jitsu users signup'
-];
+ 'jitsu users login',
+ 'jitsu login'
+]

0 comments on commit f7aee73

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