Skip to content

Commit

Permalink
[TIMOB-11869] Updated to latest node-appc auth api.
Browse files Browse the repository at this point in the history
  • Loading branch information
cb1kenobi committed Jul 3, 2013
1 parent ea5bea1 commit 14dff9f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 37 deletions.
30 changes: 18 additions & 12 deletions lib/cli.js
Expand Up @@ -347,7 +347,7 @@ CLI.prototype.login = function login(next) {
// and password, or show an error message
if (this.command.requireAuth && !appc.auth.status().loggedIn) {
var argv = this.argv,
proxy = this.config.cli.httpProxyServer,
proxy = this.config.get('cli.httpProxyServer'),
logger = this.logger,
attempts = 1,
prompt = function prompt(err) {
Expand Down Expand Up @@ -394,19 +394,25 @@ CLI.prototype.login = function login(next) {
}.bind(this),
next: function (value, go2) {
// try to login
appc.auth.login(argv.username, argv.password, function (result) {
if (result.error) {
logger.error(__('Login failed: %s', result.error.toString().replace(/\u001b\[\d+m/g, '').trim()));
// if they fail too many times, then just exit
if (++attempts > 3) {
logger.log();
process.exit(1);
appc.auth.login({
username: argv.username,
password: argv.password,
loginUrl: config.get('cli.auth.loginUrl'),
proxy: proxy,
callback: function (err, result) {
if (err) {
logger.error(__('Login failed: %s', err.toString().replace(/\u001b\[\d+m/g, '').trim()));
// if they fail too many times, then just exit
if (++attempts > 3) {
logger.log();
process.exit(1);
}
go2('username');
} else {
go2(); // done
}
go2('username');
} else {
go2(); // done
}
}, proxy);
});
}
})
}, {
Expand Down
28 changes: 17 additions & 11 deletions lib/commands/login.js
Expand Up @@ -64,18 +64,24 @@ exports.config = function (logger, config, cli) {
* @param {Function} finished - Callback when the command finishes
*/
exports.run = function (logger, config, cli, finished) {
appc.auth.login(cli.argv.username, cli.argv.password, function(result) {
if (result.error) {
if (result.error.type == 'AppcException') {
result.error.dump(logger.error);
appc.auth.login({
username: cli.argv.username,
password: cli.argv.password,
loginUrl: config.get('cli.auth.loginUrl'),
proxy: config.get('cli.httpProxyServer'),
callback: function (err, result) {
if (err) {
if (err.type == 'AppcException') {
err.dump(logger.error);
} else {
logger.error(err.toString().trim());
}
result && result.hasOwnProperty('loggedIn') && logger.error(result.loggedIn ? __('You are still logged in') : __('You are currently logged out'));
} else {
logger.error(result.error.toString().trim());
logger.log(__('Logged in successfully'));
}
result.hasOwnProperty('loggedIn') && logger.error(result.loggedIn ? __('You are still logged in') : __('You are currently logged out'));
} else {
logger.log(__('Logged in successfully'));
logger.log();
finished();
}
logger.log();
finished();
}, config.cli.httpProxyServer);
});
};
30 changes: 17 additions & 13 deletions lib/commands/logout.js
Expand Up @@ -40,20 +40,24 @@ exports.config = function (logger, config, cli) {
* @param {Function} finished - Callback when the command finishes
*/
exports.run = function (logger, config, cli, finished) {
appc.auth.logout(function (result) {
if (result.error) {
if (result.error.type == 'AppcException') {
result.error.dump(logger.error);
appc.auth.logout({
logoutUrl: config.get('cli.auth.logoutUrl'),
proxy: config.get('cli.httpProxyServer'),
callback: function (err, result) {
if (err) {
if (err.type == 'AppcException') {
err.dump(logger.error);
} else {
logger.error(err.toString().trim());
}
result && result.hasOwnProperty('loggedIn') && logger.error(result.loggedIn ? __('You are still logged in') : __('You are currently logged out'));
} else if (result.alreadyLoggedOut) {
logger.log(__('Already logged out'));
} else {
logger.error(result.error.toString().trim());
logger.log(__('Logged out successfully'));
}
result.hasOwnProperty('loggedIn') && logger.error(result.loggedIn ? __('You are still logged in') : __('You are currently logged out'));
} else if (result.alreadyLoggedOut) {
logger.log(__('Already logged out'));
} else {
logger.log(__('Logged out successfully'));
logger.log();
finished();
}
logger.log();
finished();
}, config.cli.httpProxyServer);
});
};
2 changes: 1 addition & 1 deletion lib/titanium.js
Expand Up @@ -136,7 +136,7 @@ function run() {
appId: pkginfo.about.id,
appName: pkginfo.about.name,
appGuid: 'cf5c67ed-1c3b-494b-afe0-01b958ef0f40',
directory: path.join('~', '.titanium'),
titaniumHomeDir: path.join('~', '.titanium'),
version: pkginfo.version,
deployType: 'production',
httpProxyServer: config.cli.httpProxyServer,
Expand Down

0 comments on commit 14dff9f

Please sign in to comment.