Browse files

Fix nodester#397

  • Loading branch information...
1 parent 8e045cb commit 2268ed76166288229e98ca27d1190f930c7ac5c5 @alejandro alejandro committed Jul 31, 2012
Showing with 25 additions and 14 deletions.
  1. +25 −14 lib/user.js
View
39 lib/user.js
@@ -15,12 +15,9 @@ var fs = require('fs')
, config = require('./config')
, log = require('./log')
, exists = fs.existsSync || path.existsSync
- , tty = {}
+ , tty = tty = require('tty')
;
-
-try {
- tty = require('tty');
-} catch (e) {}
+
tty.setRawMode = process.stdin.setRawMode || tty.setRawMode ;
@@ -98,36 +95,48 @@ function setKey (args) {
}
function setPass (args) {
- config.check();
- var nodeapi = new Node(config.username, config.password, config.apihost, config.apisecure);
+ var username, pass;
+ if (args.length == 1 && args[0] == 'sendtoken'){
+ return log.error('You need to provide a valid username');
+ } else if (args.length == 2 && args[0] == 'sendtoken') {
+ username = args[1];
+ } else {
+ config.check();
+ username = config.username;
+ }
+ var nodeapi = new Node(username, config.apihost, config.apisecure);
if (args.length == 1 && args[0] == 'sendtoken') {
- nodeapi.user_sendtoken(config.username, function (err, data, original) {
+ nodeapi.user_sendtoken(username, function (err, data, original) {
if (err && !data) {
-
log.error(err.message);
} else {
log.info(data.status);
log.info('token for setpass has been sent to your email!');
}
});
- } else if (args.length == 2) {
+ } else if (args.length == 2 && (args[1] != '' || args[1] != ' ')) {
nodeapi.user_setpass(args[0], args[1], function (err, data, original) {
if (err) {
-
log.error(err.message);
}
log.info('password successfully changed.');
- config.writeUser(config.username, args[0]);
+ config.writeUser(username, args[0]);
});
} else {
log.error('Argument missing: ', 'setpass sendtoken or setpass <token> <new_password>');
}
}
function setup (args) {
+ // fix args
+ args = args.map(function(v){
+ return typeof v === 'string' ? v.trim(): v;
+ }).filter(Boolean);
+
if (args.length < 2) {
log.error('Argument missing: ', '<username> <password>');
}
+
var nodeapi = new Node(args[0], args[1], config.apihost, config.apisecure);
log.info('verifying credentials');
nodeapi.apps_list(function (err, data, original) {
@@ -174,6 +183,7 @@ function register (args) {
data = data.replace('\n', '').toLowerCase().substring(0, 1);
if (data === 'y') {
askPass(function (password) {
+ if (!password) return log.error('Invalid password');
info.password = password;
log.info('creating user:', info.username, ' <' + info.email + '>');
var nodeapi = new Node("", "", config.apihost, config.apisecure);
@@ -220,7 +230,8 @@ function askPass (fn) {
}
});
} else {
- tty.setRawMode();
+ if (!tty.setRawMode) tty.setRawMode = stdin.setRawMode;
+ stdin.setRawMode(true);
stdin.addListener('data', function (data) {
data += '';
switch (data) {
@@ -267,4 +278,4 @@ var User = {
askpass: askPass
};
-module.exports = User;
+module.exports = User;

2 comments on commit 2268ed7

@alejandro
Collaborator

Fix nodester/nodester#397

@chrismatthieu Can you please update the npm package and the nodester-api too?.

@chrismatthieu
Collaborator

Thanks! The following NPMs were published:

nodester-api@0.2.0
nodester-cli@1.1.0

Please sign in to comment.