1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-22 16:29:09 +01:00

bug fixes around fetching keys for org sync

This commit is contained in:
Kyle Spearrin 2017-04-26 11:59:31 -04:00
parent a20881383e
commit 1ce4b5443b

View File

@ -84,35 +84,41 @@ function initSyncService() {
var deferred = Q.defer();
var self = this;
function setKeys(hasPrivateKey, response, d) {
if (response.organizations && response.organizations.length && !hasPrivateKey) {
self.apiService.getKeys(function (keysResponse) {
if (keysResponse.privateKey) {
self.cryptoService.setEncPrivateKey(keysResponse.privateKey).then(function () {
return self.cryptoService.setOrgKeys(response.organizations);
}, function () {
d.reject();
}).then(function () {
d.resolve();
}, function () {
d.reject();
});
}
else {
d.resolve();
}
}, function () {
d.reject();
});
}
else {
self.cryptoService.setOrgKeys(response.organizations).then(function () {
d.resolve();
}, function () {
d.reject();
});
}
}
self.apiService.getProfile(function (response) {
self.cryptoService.getPrivateKey().then(function (privateKey) {
if (response.organizations && !privateKey) {
self.apiService.getKeys(function (keysResponse) {
if (keysResponse.privateKey) {
self.cryptoService.setEncPrivateKey(keysResponse.privateKey).then(function () {
return self.cryptoService.setOrgKeys(response.organizations);
}, function () {
deferred.reject();
}).then(function () {
deferred.resolve();
}, function () {
deferred.reject();
});
}
else {
deferred.resolve();
}
}, function () {
deferred.reject();
});
}
else {
self.cryptoService.setOrgKeys(response.organizations).then(function () {
deferred.resolve();
}, function () {
deferred.reject();
});
}
setKeys(!!privateKey, response, deferred);
}, function () {
setKeys(false, response, deferred);
});
}, function () {
deferred.reject();