Permalink
Browse files

[fix minor] Update the timeout code for .checkVersion(). Minor code f…

…ormatting in commands/users.js
  • Loading branch information...
1 parent bfdd878 commit dddaf8bbdbff668503561f04b9ad340f51f91247 @indexzero indexzero committed Aug 12, 2011
Showing with 45 additions and 53 deletions.
  1. +1 −15 lib/jitsu.js
  2. +1 −1 lib/jitsu/api/users.js
  3. +34 −32 lib/jitsu/commands/users.js
  4. +4 −0 lib/jitsu/properties.js
  5. +5 −4 lib/jitsu/utils/index.js
  6. +0 −1 test/helpers/mock-helpers.js
View
@@ -87,21 +87,7 @@ jitsu.start = function (argv, callback) {
winston.info('Welcome to ' + 'Nodejitsu'.grey);
winston.info('It worked if it ends with ' + 'Nodejitsu'.grey + ' ok'.green.bold);
- jitsu.utils.checkVersion(function (handler) {
- var oldCallback = callback;
- callback = function() {
- if(handler.req) {
- var timer = setTimeout(function() {
- if(handler.req) {
- handler.req.abort();
- }
- handler.on('end', function() {
- clearTimeout(timer);
- })
- }, 200);
- }
- oldCallback.call(this, arguments);
- }
+ jitsu.utils.checkVersion(function () {
jitsu.config.load(function (err) {
if (err) {
callback(err);
View
@@ -81,7 +81,7 @@ Users.prototype.forgot = function (username, callback) {
});
};
-Users.prototype.put = function (username, object, callback) {
+Users.prototype.update = function (username, object, callback) {
this.request('PUT', ['users', username], object, callback, function (res, result) {
callback(null, result);
});
@@ -41,8 +41,8 @@ users.create = function (username, callback) {
}
function getPassword() {
- jitsu.prompt.get(['password', { name:'confirm password', hidden: true }], function (err, result) {
- if (result['password'] === result['confirm password'] && result['password'] !== "") {
+ jitsu.prompt.get(['password', 'confirm password'], function (err, result) {
+ if (result['password'] === result['confirm password'] && result['password'] !== '') {
password = result.password;
jitsu.users.create({
username: username,
@@ -231,24 +231,10 @@ users.forgot = function (username, shake, callback) {
}
winston.info('Check your email for instructions on resetting your password.');
- callback(new Error('Password Reset Pending.'));
+ callback();
});
};
-var forgotResetHelper = function (username, shake, callback) {
- jitsu.config.set('username', username);
- jitsu.config.set('password', shake);
- jitsu.users.auth(function (err) {
- if (err) {
- winston.error('Invalid username and shake combo');
- callback(err);
- }
- else {
- users.changepassword(callback);
- }
- });
-}
-
users.forgot.usage = [
'Sends the password reset email to the user with the specified `username`.',
'',
@@ -264,43 +250,59 @@ users.forgot.usage = [
// Change the password for the user
//
users.changepassword = function (callback) {
- var getPassword = function () {
- jitsu.prompt.get(['password', {name:'confirm password', hidden: true}], function (err, result) {
+ (function getPassword () {
+ jitsu.prompt.get(['password', 'confirm password'], function (err, result) {
if (result['password'] === result['confirm password'] && result['password'] !== "") {
- var options = {password:result['password']};
- jitsu.users.put(jitsu.config.get('username'), options, function(err) {
- if (err) {
- return callback(err);
- }
- jitsu.config.save(callback);
+ var options = {
+ password: result['password']
+ };
+
+ jitsu.users.update(jitsu.config.get('username'), options, function (err) {
+ return err
+ ? callback(err)
+ : jitsu.config.save(callback);
});
}
else {
- if (result['password'] === "") {
+ if (result['password'] === '') {
winston.error('You password must have characters in it');
- } else {
+ }
+ else {
winston.error('The entered passwords do not match');
}
+
getPassword();
}
});
- };
- getPassword();
+ })();
}
users.changepassword.usage = [
'Used to change the user password',
'',
'jitsu users changepassword',
-]
+];
users.login = function(callback) {
jitsu.setupUserNoWarn(callback);
-}
+};
users.login.usage = [
'Allows the user to login',
'',
'jitsu users login',
'jitsu login'
-]
+];
+
+function forgotResetHelper (username, shake, callback) {
+ jitsu.config.set('username', username);
+ jitsu.config.set('password', shake);
+ jitsu.users.auth(function (err) {
+ if (err) {
+ winston.error('Invalid username and shake combo');
+ return callback(err);
+ }
+
+ users.changepassword(callback);
+ });
+}
View
@@ -17,6 +17,10 @@ properties.properties = {
name: 'password',
hidden: true
},
+ 'confirm password': {
+ name: 'confirm password',
+ hidden: true
+ },
inviteCode: {
name: 'invite code',
message: 'Invite Code',
View
@@ -147,8 +147,9 @@ utils.checkVersion = function (callback) {
// Check the GitHub tags for `jitsu` to see if the current
// version is outdated. If it is not make sure to message the user at the end.
//
- var handler = request({
- uri: 'http://registry.npmjs.org/jitsu/latest'
+ request({
+ uri: 'http://registry.npmjs.org/jitsu/latest',
+ timeout: 200
}, function (err, res, body) {
if (!responded) {
responded = true;
@@ -169,8 +170,8 @@ utils.checkVersion = function (callback) {
// of an upgrade at the next possible opportunity.
//
}
+
+ callback();
}
});
-
- callback(handler);
};
@@ -198,7 +198,6 @@ exports.runJitsuCommand = function () {
that.callback.apply(that, arguments);
});
-
}
};

0 comments on commit dddaf8b

Please sign in to comment.