Print login failed error message once instead of twice

This commit is contained in:
Emily Stark
2014-02-06 10:14:32 -08:00
parent a4a83c1b31
commit aabed4665c
2 changed files with 18 additions and 7 deletions

View File

@@ -434,6 +434,8 @@ var logInToGalaxy = function (galaxyName) {
// include:
// - retry: if true, then if the user gets the password wrong,
// reprompt.
// - suppressErrorMessage: true if the function should not print an
// error message to stderr if the login fails
var doInteractivePasswordLogin = function (options) {
var loginData = {};
@@ -445,7 +447,9 @@ var doInteractivePasswordLogin = function (options) {
throw new Error("Need username or email");
var loginFailed = function () {
process.stderr.write("Login failed.\n");
if (! options.suppressErrorMessage) {
process.stderr.write("Login failed.\n");
}
};
var conn = authConn();
@@ -493,6 +497,8 @@ var doInteractivePasswordLogin = function (options) {
return true;
};
exports.doInteractivePasswordLogin = doInteractivePasswordLogin;
exports.loginCommand = function (options) {
config.printUniverseBanner();

View File

@@ -153,13 +153,18 @@ var authedRpc = function (options) {
if (infoResult.statusCode === 403 && rpcOptions.promptIfAuthFails) {
// Our authentication didn't validate, so prompt the user to log in
// again, and resend the RPC if the login succeeds.
var loginResult = auth.loginCommand(_.extend({}, rpcOptions, {
overwriteExistingToken: true
}));
if (loginResult === 0) {
// If the login prompt succeeded, then resend the RPC with the
// original options.
var username = utils.readLine({ prompt: "Username: " });
var loginOptions = {
username: username,
suppressErrorMessage: true
};
if (auth.doInteractivePasswordLogin(loginOptions)) {
return authedRpc(options);
} else {
return {
statusCode: 403,
errorMessage: "login failed."
};
}
}