Skip to content

Commit

Permalink
Merge pull request #4 from bryan-m-hughes/timob-9986
Browse files Browse the repository at this point in the history
Timob 9986 Login/logout
  • Loading branch information
cb1kenobi committed Sep 13, 2012
2 parents c6d8ccf + 84a57a2 commit f72c393
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
10 changes: 9 additions & 1 deletion lib/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* See the LICENSE file for more information.
*/

var appc = require('node-appc');

exports.config = function (logger, config, cli) {
return {
desc: __('logs into the Appcelerator network'),
Expand Down Expand Up @@ -37,5 +39,11 @@ exports.config = function (logger, config, cli) {
};

exports.run = function (logger, config, cli) {
dump(cli.argv);
appc.auth.login(cli.argv.username, cli.argv.password, function(result) {
if (result.error) {
logger.log(__('Login failed: %s', result.error) + '\n');
} else {
logger.log(__('Logged in successfully') + '\n');
}
});
};
10 changes: 9 additions & 1 deletion lib/commands/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
* See the LICENSE file for more information.
*/

var appc = require('node-appc');

exports.config = function (logger, config, cli) {
return {
desc: __('logs out of the Appcelerator network')
};
};

exports.run = function (logger, config, cli) {
dump(cli.argv);
appc.auth.logout(function (result) {
if (result.error) {
logger.log(__('Logout failed: %s', result.error) + '\n');
} else {
logger.log(__('Logged out successfully') + '\n');
}
});
};
58 changes: 45 additions & 13 deletions lib/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,59 @@
* See the LICENSE file for more information.
*/

var appc = require('node-appc'),
async = require('async');

exports.config = function (logger, config, cli) {
return {
desc: __('displays session and project information'),
desc: __('displays session information'),
skipBanner: true,
options: {
output: {
alias: 'o',
abbr: 'o',
default: 'report',
desc: 'output format',
values: ['report', 'json', 'xml']
}
},
args: [
{
desc: __('the directory where the project is located'),
name: 'project-dir',
required: true
desc: __('output format'),
values: ['report', 'json']
}
]
}
};
};

exports.run = function (logger, config, cli) {
dump(cli.argv);

async.parallel({
auth: function (next) {
appc.auth.status(function(status) {
next(null, status);
});
},
project: function (next) {
// TODO: Implement project status
next(null, {});
}},
function (err, results) {

switch(cli.argv.output) {
case 'report':
logger.banner();
if (results.auth.loggedIn) {
logger.log(__('You are currently logged in') + '\n');
} else {
if (results.auth.expired) {
logger.log(__('You are not currently logged in. You must log in before using authenticated commands.') + '\n');
} else {
logger.log(__('You are not currently logged in. Offline support available for %s.',
appc.time.prettyDiff(Date.now(), results.auth.offlineExpires, {
showFullName: true,
hideMS: true,
colorize: true
})) + '\n');
}
}
break;
case 'json':
logger.log(JSON.stringify(results.auth));
break;
}
});
};
4 changes: 4 additions & 0 deletions locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@
"Invalid username": "Invalid username",
"Password": "Password",
"Invalid password": "Invalid password",
"displays session information": "displays session information",
"You are currently logged in": "You are currently logged in",
"You are not currently logged in. Offline support available for %s": "You are not currently logged in. Offline support available for %s",
"You are not currently logged in. You must log in before using authenticated commands": "You are not currently logged in. You must log in before using authenticated commands",
"Searching for %s Titanium plugin": {
"one": "Searching for %s Titanium plugin",
"other": "Searching for %s Titanium plugins"
Expand Down

0 comments on commit f72c393

Please sign in to comment.