diff --git a/src/cloud.js b/src/cloud.js index 3b3081604b..7c94713f2c 100755 --- a/src/cloud.js +++ b/src/cloud.js @@ -282,12 +282,14 @@ Cloud.prototype.checkCredentials = function (onSuccess, onError, response) { if (user.username) { myself.username = user.username; myself.verified = user.verified; + myself.previous_username_admin = user.previous_username_admin; } if (onSuccess) { onSuccess.call( null, user.username, user.role, + user.previous_username_admin, response ? JSON.parse(response) : null ); } @@ -327,6 +329,34 @@ Cloud.prototype.logout = function (onSuccess, onError) { ); }; +Cloud.prototype.logoutAlias = function (onSuccess, onError) { + var myself = this; + this.getCurrentUser( + function (user) { + if (user.username && user.previous_username_admin) { + myself.login( + user.previous_username_admin, + '', // password is irrelevant, but can't be null + false, // ignored, will use the Admin's settings saved in the backend + function (username, role, previous_username_admin, response) { + alert( + response.message, + function () { + onSuccess.call(); + sessionStorage.previous_username_admin = previous_username_admin; + sessionStorage.username = username; + sessionStorage.role = role; + } + ); + }, + onError + ); + } + }, + onError + ); +} + Cloud.prototype.login = function ( username, password,