Skip to content

Commit

Permalink
logout more nicely during setup
Browse files Browse the repository at this point in the history
  • Loading branch information
David Middlecamp committed Apr 29, 2014
1 parent 0184256 commit 74a828b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
28 changes: 18 additions & 10 deletions js/commands/SetupCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,25 @@ SetupCommand.prototype = extend(BaseCommand.prototype, {
//2.) confirm pass,
//3.) create user,

function (switchAccounts) {
if (!switchAccounts) {
//skip this then
function(switchAccounts) {
if (switchAccounts) {
return cloud.logout(true);
}
else {
return when.resolve();
}
},

//lets not pretend we're logged in when switching accounts.
if (settings.access_token) {
api.clearToken();
cloud.logout();
function () {
settings = settings.loadOverrides();
if (!settings.access_token) {
//need to login
return that.login_or_create_account(api);
}
else {
//already / still logged in
return when.resolve();
}

return that.login_or_create_account(api);
},
function () {
var token = api.getToken();
Expand All @@ -150,6 +156,7 @@ SetupCommand.prototype = extend(BaseCommand.prototype, {
}

var getCoreID = function () {
//todo: timeout fail after, ~5 seconds?
return serial.identifyCore();
};
var recoveryFn = function () {
Expand Down Expand Up @@ -264,6 +271,7 @@ SetupCommand.prototype = extend(BaseCommand.prototype, {


when(allDone).then(function () {
settings = settings.loadOverrides();

console.log("You've successfully setup your core: " + coreName + " (" + coreID + ")");
console.log("");
Expand Down Expand Up @@ -364,7 +372,7 @@ SetupCommand.prototype = extend(BaseCommand.prototype, {
return when.resolve(token);
}
]);
return utilities.pipeDeferred(createAccountDone, tmp);
utilities.pipeDeferred(createAccountDone, tmp);
});

return tmp.promise;
Expand Down
1 change: 1 addition & 0 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ settings.loadOverrides = function () {
catch (ex) {
console.error('There was an error reading ' + settings.overrides + ': ', ex);
}
return settings;
};
settings.override = function (key, value) {
if (!settings.overrides) {
Expand Down

0 comments on commit 74a828b

Please sign in to comment.