1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

fix sync bugs on login/logout

This commit is contained in:
Kyle Spearrin 2017-01-17 21:43:26 -05:00
parent 80945bd3bc
commit f84bfcb19a
6 changed files with 24 additions and 23 deletions

View File

@ -622,7 +622,7 @@ function fullSync(override) {
syncService.getLastSync(function (lastSync) { syncService.getLastSync(function (lastSync) {
var now = new Date(); var now = new Date();
if (override || !lastSync || (now - lastSync) >= syncInternal) { if (override || !lastSync || (now - lastSync) >= syncInternal) {
syncService.fullSync(override, function () { }); syncService.fullSync(override || false, function () { });
} }
}); });
} }

View File

@ -2,7 +2,7 @@
.module('bit.services') .module('bit.services')
.factory('authService', function (cryptoService, apiService, userService, tokenService, $q, $rootScope, loginService, .factory('authService', function (cryptoService, apiService, userService, tokenService, $q, $rootScope, loginService,
folderService) { folderService, settingsService, syncService) {
var _service = {}; var _service = {};
_service.logIn = function (email, masterPassword) { _service.logIn = function (email, masterPassword) {
@ -66,19 +66,24 @@
return deferred.promise; return deferred.promise;
}; };
// TODO: Fix callback hell by moving to promises
_service.logOut = function (callback) { _service.logOut = function (callback) {
userService.getUserId(function (userId) { userService.getUserId(function (userId) {
tokenService.clearToken(function () { syncService.setLastSync(new Date(0), function () {
cryptoService.clearKey(function () { settingsService.clear(function () {
cryptoService.clearKeyHash(function () { tokenService.clearToken(function () {
userService.clearUserId(function () { cryptoService.clearKey(function () {
userService.clearEmail(function () { cryptoService.clearKeyHash(function () {
loginService.clear(userId, function () { userService.clearUserId(function () {
folderService.clear(userId, function () { userService.clearEmail(function () {
$rootScope.vaultLogins = null; loginService.clear(userId, function () {
$rootScope.vaultFolders = null; folderService.clear(userId, function () {
chrome.runtime.sendMessage({ command: 'loggedOut' }); $rootScope.vaultLogins = null;
callback(); $rootScope.vaultFolders = null;
chrome.runtime.sendMessage({ command: 'loggedOut' });
callback();
});
});
}); });
}); });
}); });

View File

@ -42,4 +42,7 @@
}) })
.factory('constantsService', function () { .factory('constantsService', function () {
return chrome.extension.getBackgroundPage().constantsService; return chrome.extension.getBackgroundPage().constantsService;
})
.factory('settingsService', function () {
return chrome.extension.getBackgroundPage().settingsService;
}); });

View File

@ -13,7 +13,7 @@
if (syncOnLoad) { if (syncOnLoad) {
$scope.$on('$viewContentLoaded', function () { $scope.$on('$viewContentLoaded', function () {
$timeout(function () { $timeout(function () {
syncService.fullSync(function () { }); syncService.fullSync(true, function () { });
}, 0); }, 0);
}); });
} }

View File

@ -137,11 +137,8 @@ function initLoginService() {
var eqDomainsPromise = self.settingsService.getEquivalentDomains().then(function (eqDomains) { var eqDomainsPromise = self.settingsService.getEquivalentDomains().then(function (eqDomains) {
var matchingDomains = []; var matchingDomains = [];
for (var i = 0; i < eqDomains.length; i++) { for (var i = 0; i < eqDomains.length; i++) {
for (var j = 0; j < eqDomains[i].length; j++) { if (eqDomains[i].length && eqDomains[i].indexOf(domain) >= 0) {
if (eqDomains[i][j] === domain) { matchingDomains = matchingDomains.concat(eqDomains[i]);
matchingDomains = matchingDomains.concat(eqDomains[i]);
break;
}
} }
} }

View File

@ -230,10 +230,6 @@ function initSyncService() {
throw 'callback function required'; throw 'callback function required';
} }
if (!(date instanceof Date)) {
throw 'date must be a Date object';
}
this.userService.getUserId(function (userId) { this.userService.getUserId(function (userId) {
var lastSyncKey = 'lastSync_' + userId; var lastSyncKey = 'lastSync_' + userId;