diff --git a/src/background.js b/src/background.js index 909c33afbe..1c9c42eb2d 100644 --- a/src/background.js +++ b/src/background.js @@ -4,3 +4,4 @@ var apiService = new ApiService(tokenService); var userService = new UserService(tokenService, apiService); var siteService = new SiteService(cryptoService, userService, apiService); var folderService = new FolderService(cryptoService, userService, apiService); +var syncService = new SyncService(siteService, folderService, userService, apiService); diff --git a/src/manifest.json b/src/manifest.json index 59315fe6e6..4a1b0ebcff 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -28,6 +28,7 @@ "services/userService.js", "services/folderService.js", "services/siteService.js", + "services/syncService.js", "background.js" ] }, diff --git a/src/models/api/responseModels.js b/src/models/api/responseModels.js index a569ec48ef..9d2c01f8f9 100644 --- a/src/models/api/responseModels.js +++ b/src/models/api/responseModels.js @@ -2,7 +2,7 @@ this.id = response.Id; this.folderId = response.FolderId; this.type = response.Type; - this.favorite = response.favorite; + this.favorite = response.Favorite; this.data = response.Data; this.revisionDate = response.RevisionDate; }; @@ -21,7 +21,7 @@ var SiteResponse = function (response) { this.username = response.Username; this.password = response.Password; this.notes = response.Notes; - this.favorite = response.favorite; + this.favorite = response.Favorite; this.revisionDate = response.RevisionDate; if(response.Folder) { @@ -47,7 +47,7 @@ var TokenResponse = function (response) { }; var ListResponse = function (data) { - this.Data = data; + this.data = data; }; var ErrorResponse = function (response) { diff --git a/src/models/dataModels.js b/src/models/dataModels.js index d8ac1365ac..cba28b4918 100644 --- a/src/models/dataModels.js +++ b/src/models/dataModels.js @@ -1,41 +1,43 @@ var FolderData = function (response, userId) { - var data = null; + this.id = response.id; + this.userId = userId; + if (response instanceof FolderResponse) { - data = response; + this.name = response.name; } else if (response instanceof CipherResponse) { - data = response.Data; + this.name = response.data.Name; } else { throw 'unsupported instance'; } - this.id = response.id; - this.userId = userId; - this.name = data.name; this.revisionDate = response.revisionDate; }; var SiteData = function (response, userId) { - var data = null; + this.id = response.id; + this.folderId = response.folderId; + this.userId = userId; + if (response instanceof SiteResponse) { - data = response; + this.name = response.name; + this.uri = response.uri; + this.username = response.username; + this.password = response.password; + this.notes = response.notes; } else if (response instanceof CipherResponse) { - data = response.Data; + this.name = response.data.Name; + this.uri = response.data.Uri; + this.username = response.data.Username; + this.password = response.data.Password; + this.notes = response.notes = response.data.Notes;; } else { throw 'unsupported instance'; } - this.id = response.id; - this.folderId = response.folderId; - this.userId = userId; - this.name = data.name; - this.uri = data.uri; - this.username = data.username; - this.password = data.password; - this.notes = data.notes; this.favorite = response.favorite; this.revisionDate = response.revisionDate; }; diff --git a/src/popup/app/services/backgroundService.js b/src/popup/app/services/backgroundService.js index 456cb3cb10..aa7b3a7f96 100644 --- a/src/popup/app/services/backgroundService.js +++ b/src/popup/app/services/backgroundService.js @@ -18,4 +18,7 @@ }) .factory('siteService', function () { return chrome.extension.getBackgroundPage().siteService; + }) + .factory('syncService', function () { + return chrome.extension.getBackgroundPage().syncService; }); diff --git a/src/popup/app/settings/settingsController.js b/src/popup/app/settings/settingsController.js index 3fcc35e4d0..44fc2dde8b 100644 --- a/src/popup/app/settings/settingsController.js +++ b/src/popup/app/settings/settingsController.js @@ -1,7 +1,13 @@ angular .module('bit.settings') - .controller('settingsController', function ($scope, loginService, $state) { + .controller('settingsController', function ($scope, loginService, $state, syncService) { + $scope.sync = function () { + syncService.fullSync(function () { + alert('Sync done!'); + }); + }; + $scope.logOut = function (model) { loginService.logOut(function () { $state.go('login'); diff --git a/src/popup/app/settings/views/settings.html b/src/popup/app/settings/views/settings.html index 1b65c77e11..1cac0d2c2c 100644 --- a/src/popup/app/settings/views/settings.html +++ b/src/popup/app/settings/views/settings.html @@ -1,6 +1,15 @@ 
+
+ Manage +
+ + Folders + + + Sync +
Current Session
diff --git a/src/popup/app/vault/vaultController.js b/src/popup/app/vault/vaultController.js index 9d2bd62487..707349737f 100644 --- a/src/popup/app/vault/vaultController.js +++ b/src/popup/app/vault/vaultController.js @@ -7,14 +7,11 @@ $scope.folders = []; $scope.focusedSiteId = null; - $scope.$on("$ionicView.enter", function (event, data) { + $scope.$on('$ionicView.enter', function (event, data) { loadVault(); }); function loadVault() { - $scope.sites = []; - $scope.folders = []; - var decSites = []; var decFolders = [{ id: null, @@ -25,12 +22,12 @@ siteService.getAll(function (sites) { var promises = []; - for (var i = 0; i < folders.length; i++) { + for (var i = 1; i < folders.length; i++) { decFolders.push({ id: folders[i].id }); - var folderNamePromise = cipherService.decrypt(sites[i].name, i); + var folderNamePromise = cipherService.decrypt(folders[i].name, i); promises.push(folderNamePromise); folderNamePromise.then(function (obj) { decFolders[obj.index].name = obj.val; @@ -65,6 +62,14 @@ }); } + $scope.folderSort = function (item) { + if (!item.id) { + return ''; + } + + return item.name.toLowerCase(); + }; + $scope.viewSite = function (site) { $scope.focusedSiteId = site.id; $ionicModal.fromTemplateUrl('app/vault/views/vaultViewSite.html', { @@ -111,7 +116,7 @@ $scope.focusedSiteId = null; }; - $scope.$on('modal.hidden', function () { + $scope.$on('closeViewSite.hidden', function () { console.log('modal hidden'); loadVault(); }); diff --git a/src/services/apiService.js b/src/services/apiService.js index c6e6b2f337..4b7fe3bc5b 100644 --- a/src/services/apiService.js +++ b/src/services/apiService.js @@ -203,8 +203,8 @@ function initApiService() { dataType: 'json', success: function (response) { var data = []; - for (var i = 0; i < response.length; i++) { - data.push(new CipherResponse(response[i])); + for (var i = 0; i < response.Data.length; i++) { + data.push(new CipherResponse(response.Data[i])); } success(new ListResponse(data)) diff --git a/src/services/syncService.js b/src/services/syncService.js index 1429a4b507..d182383b05 100644 --- a/src/services/syncService.js +++ b/src/services/syncService.js @@ -15,39 +15,39 @@ function initSyncService() { } var self = this; - this.userService.isAuthenticated(function (isAuthenticated) { + self.userService.isAuthenticated(function (isAuthenticated) { if (!isAuthenticated) { callback(false); return; } - syncStarted(); - var now = new Date(); - var ciphers = self.apiService.getCiphers(function (response) { - var sites = {}; - var folders = {}; + self.userService.getUserId(function (userId) { + syncStarted(); + var now = new Date(); + var ciphers = self.apiService.getCiphers(function (response) { + var sites = {}; + var folders = {}; - for (var i = 0; i < response.Data.lenth; i++) { - var data = response.Data[i]; - if (data.type === 1) { - sites[data.id] = new SiteData(data); + for (var i = 0; i < response.data.length; i++) { + var data = response.data[i]; + if (data.type === 1) { + sites[data.id] = new SiteData(data, userId); + } + else if (data.type === 0) { + folders[data.id] = new FolderData(data, userId); + } } - else if (data.type === 0) { - folders[data.id] = new FolderData(data); - } - } - folderService.replace(folders, function () { - siteService.replace(sites, function () { - setLastSync(now, function () { - syncCompleted(true); - callback(true); + self.folderService.replace(folders, function () { + self.siteService.replace(sites, function () { + self.setLastSync(now, function () { + syncCompleted(true); + callback(true); + }); }); }); - }); - - }, handleError); - + }, handleError); + }); }); }; @@ -71,12 +71,12 @@ function initSyncService() { self.userService.getUserId(function (userId) { self.folderService.getAll(function (folders) { var localFolders = {}; - for (var i = 0; i < folders.lenth; i++) { + for (var i = 0; i < folders.length; i++) { localFolders[folders[i].id] = folders[i]; } var data = []; - for (var j = 0; j < serverFolders.lenth; j++) { + for (var j = 0; j < serverFolders.length; j++) { var serverFolder = serverFolders[j]; var existingLocalFolder = localFolders[serverFolder.id]; @@ -105,12 +105,12 @@ function initSyncService() { self.userService.getUserId(function (userId) { self.siteService.getAll(function (sites) { var localSites = {}; - for (var i = 0; i < sites.lenth; i++) { + for (var i = 0; i < sites.length; i++) { localSites[sites[i].id] = sites[i]; } var data = []; - for (var j = 0; j < serverSites.lenth; j++) { + for (var j = 0; j < serverSites.length; j++) { var serverSite = serverSites[j]; var existingLocalSite = localSites[serverSite.id]; diff --git a/src/services/userService.js b/src/services/userService.js index 85c289a2e4..e3e8dde931 100644 --- a/src/services/userService.js +++ b/src/services/userService.js @@ -40,7 +40,7 @@ function initUserService() { } var decodedToken = this.tokenService.decodeToken(token); - var twoFactor = decodedToken.authmethod === "TwoFactor"; + var twoFactor = decodedToken.authmethod === 'TwoFactor'; _userProfile = { id: decodedToken.nameid,