1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-18 02:41:15 +02:00

share profile promise result when called at same

time
This commit is contained in:
Kyle Spearrin 2017-03-27 22:22:56 -04:00
parent 35e0f27f52
commit 4d2cae0b0f
2 changed files with 20 additions and 17 deletions

View File

@ -69,27 +69,30 @@ angular
return deferred.promise; return deferred.promise;
}; };
var _setDeferred = null;
_service.setUserProfile = function () { _service.setUserProfile = function () {
var deferred = $q.defer(); if (_setDeferred && _setDeferred.promise.$$state.status === 0) {
return _setDeferred.promise;
}
_setDeferred = $q.defer();
var token = tokenService.getToken(); var token = tokenService.getToken();
if (!token) { if (!token) {
deferred.reject(); _setDeferred.reject();
return deferred.promise; return _setDeferred.promise;
} }
var decodedToken = jwtHelper.decodeToken(token); var decodedToken = jwtHelper.decodeToken(token);
_userProfile = {
id: decodedToken.name,
email: decodedToken.email
};
apiService.accounts.getProfile({}, function (profile) { apiService.accounts.getProfile({}, function (profile) {
_userProfile.extended = { _userProfile = {
name: profile.Name, id: decodedToken.name,
twoFactorEnabled: profile.TwoFactorEnabled, email: decodedToken.email,
culture: profile.Culture extended: {
name: profile.Name,
twoFactorEnabled: profile.TwoFactorEnabled,
culture: profile.Culture
}
}; };
if (profile.Organizations) { if (profile.Organizations) {
@ -106,13 +109,13 @@ angular
_userProfile.organizations = orgs; _userProfile.organizations = orgs;
cryptoService.setOrgKeys(orgs); cryptoService.setOrgKeys(orgs);
deferred.resolve(_userProfile); _setDeferred.resolve(_userProfile);
} }
}, function () { }, function () {
deferred.reject(); _setDeferred.reject();
}); });
return deferred.promise; return _setDeferred.promise;
}; };
_service.addProfileOrganization = function (org) { _service.addProfileOrganization = function (org) {

View File

@ -26,7 +26,7 @@ angular
}; };
_service.setOrgKeys = function (orgKeysCt, privateKey) { _service.setOrgKeys = function (orgKeysCt, privateKey) {
if (!orgKeysCt.length) { if (!orgKeysCt || Object.keys(orgKeysCt).length === 0) {
return; return;
} }