Skip to content

Commit

Permalink
Fix nodester#397
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro committed Jul 31, 2012
1 parent 8e045cb commit 2268ed7
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions lib/user.js
Expand Up @@ -15,12 +15,9 @@ var fs = require('fs')
, config = require('./config') , config = require('./config')
, log = require('./log') , log = require('./log')
, exists = fs.existsSync || path.existsSync , exists = fs.existsSync || path.existsSync
, tty = {} , tty = tty = require('tty')
; ;


try {
tty = require('tty');
} catch (e) {}


tty.setRawMode = process.stdin.setRawMode || tty.setRawMode ; tty.setRawMode = process.stdin.setRawMode || tty.setRawMode ;


Expand Down Expand Up @@ -98,36 +95,48 @@ function setKey (args) {
} }


function setPass (args) { function setPass (args) {
config.check(); var username, pass;
var nodeapi = new Node(config.username, config.password, config.apihost, config.apisecure); 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') { 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) { if (err && !data) {

log.error(err.message); log.error(err.message);
} else { } else {
log.info(data.status); log.info(data.status);
log.info('token for setpass has been sent to your email!'); 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) { nodeapi.user_setpass(args[0], args[1], function (err, data, original) {
if (err) { if (err) {

log.error(err.message); log.error(err.message);
} }
log.info('password successfully changed.'); log.info('password successfully changed.');
config.writeUser(config.username, args[0]); config.writeUser(username, args[0]);
}); });
} else { } else {
log.error('Argument missing: ', 'setpass sendtoken or setpass <token> <new_password>'); log.error('Argument missing: ', 'setpass sendtoken or setpass <token> <new_password>');
} }
} }


function setup (args) { function setup (args) {
// fix args
args = args.map(function(v){
return typeof v === 'string' ? v.trim(): v;
}).filter(Boolean);

if (args.length < 2) { if (args.length < 2) {
log.error('Argument missing: ', '<username> <password>'); log.error('Argument missing: ', '<username> <password>');
} }

var nodeapi = new Node(args[0], args[1], config.apihost, config.apisecure); var nodeapi = new Node(args[0], args[1], config.apihost, config.apisecure);
log.info('verifying credentials'); log.info('verifying credentials');
nodeapi.apps_list(function (err, data, original) { nodeapi.apps_list(function (err, data, original) {
Expand Down Expand Up @@ -174,6 +183,7 @@ function register (args) {
data = data.replace('\n', '').toLowerCase().substring(0, 1); data = data.replace('\n', '').toLowerCase().substring(0, 1);
if (data === 'y') { if (data === 'y') {
askPass(function (password) { askPass(function (password) {
if (!password) return log.error('Invalid password');
info.password = password; info.password = password;
log.info('creating user:', info.username, ' <' + info.email + '>'); log.info('creating user:', info.username, ' <' + info.email + '>');
var nodeapi = new Node("", "", config.apihost, config.apisecure); var nodeapi = new Node("", "", config.apihost, config.apisecure);
Expand Down Expand Up @@ -220,7 +230,8 @@ function askPass (fn) {
} }
}); });
} else { } else {
tty.setRawMode(); if (!tty.setRawMode) tty.setRawMode = stdin.setRawMode;
stdin.setRawMode(true);
stdin.addListener('data', function (data) { stdin.addListener('data', function (data) {
data += ''; data += '';
switch (data) { switch (data) {
Expand Down Expand Up @@ -267,4 +278,4 @@ var User = {
askpass: askPass askpass: askPass
}; };


module.exports = User; module.exports = User;

2 comments on commit 2268ed7

@alejandro
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix nodester/nodester#397

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

@chrismatthieu
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The following NPMs were published:

nodester-api@0.2.0
nodester-cli@1.1.0

Please sign in to comment.