1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-26 17:08:33 +01: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;
};
var _setDeferred = null;
_service.setUserProfile = function () {
var deferred = $q.defer();
if (_setDeferred && _setDeferred.promise.$$state.status === 0) {
return _setDeferred.promise;
}
_setDeferred = $q.defer();
var token = tokenService.getToken();
if (!token) {
deferred.reject();
return deferred.promise;
_setDeferred.reject();
return _setDeferred.promise;
}
var decodedToken = jwtHelper.decodeToken(token);
_userProfile = {
id: decodedToken.name,
email: decodedToken.email
};
apiService.accounts.getProfile({}, function (profile) {
_userProfile.extended = {
name: profile.Name,
twoFactorEnabled: profile.TwoFactorEnabled,
culture: profile.Culture
_userProfile = {
id: decodedToken.name,
email: decodedToken.email,
extended: {
name: profile.Name,
twoFactorEnabled: profile.TwoFactorEnabled,
culture: profile.Culture
}
};
if (profile.Organizations) {
@ -106,13 +109,13 @@ angular
_userProfile.organizations = orgs;
cryptoService.setOrgKeys(orgs);
deferred.resolve(_userProfile);
_setDeferred.resolve(_userProfile);
}
}, function () {
deferred.reject();
_setDeferred.reject();
});
return deferred.promise;
return _setDeferred.promise;
};
_service.addProfileOrganization = function (org) {

View File

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