From 1520f5e0dfe4bccd9fe3c1d9d1141e8c159204b0 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 5 Sep 2016 23:23:12 -0400 Subject: [PATCH] value fixes --- src/models/domainModels.js | 14 ++++++------ src/popup/app/vault/vaultController.js | 30 ++++++++++++++++++-------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/models/domainModels.js b/src/models/domainModels.js index b4bae908bd..ba6f5ce7be 100644 --- a/src/models/domainModels.js +++ b/src/models/domainModels.js @@ -1,5 +1,6 @@ var CipherString = function (encryptedString) { this.encryptedString = encryptedString; + this.decryptedValue = null; if (encryptedString) { this.initializationVector = this.encryptedString.split('|')[0]; @@ -8,18 +9,16 @@ var CipherString = function (encryptedString) { }; !function () { - var _decryptedValue = null; - CipherString.prototype.decrypt = function (callback) { - if (!_decryptedValue) { + if (!this.decryptedValue) { var cryptoService = chrome.extension.getBackgroundPage().cryptoService; cryptoService.decrypt(this, function (decValue) { - _decryptedValue = decValue; - callback(_decryptedValue); + this.decryptedValue = decValue; + callback(this.decryptedValue); }); } else { - callback(_decryptedValue); + callback(this.decryptedValue); } }; }(); @@ -27,6 +26,7 @@ var CipherString = function (encryptedString) { var Site = function (obj, alreadyEncrypted) { this.id = obj.id ? obj.id : null; this.folderId = obj.folderId ? obj.folderId : null; + this.favorite = obj.favorite ? true : false; if (alreadyEncrypted === true) { this.name = obj.name ? obj.name : null; @@ -42,8 +42,6 @@ var Site = function (obj, alreadyEncrypted) { this.password = obj.password ? new CipherString(obj.password) : null; this.notes = obj.notes ? new CipherString(obj.notes) : null; } - - this.favorite = obj.favorite ? true : false; }; var Folder = function (obj, alreadyEncrypted) { diff --git a/src/popup/app/vault/vaultController.js b/src/popup/app/vault/vaultController.js index d20d4c6f04..bd885ce58e 100644 --- a/src/popup/app/vault/vaultController.js +++ b/src/popup/app/vault/vaultController.js @@ -21,9 +21,11 @@ id: folders[i].id }); - promises.push(decrypt(folders[j].name, i).then(function (obj) { + var folderNamePromise = decrypt(sites[i].name, i); + promises.push(folderNamePromise); + folderNamePromise.then(function (obj) { decFolders[obj.index].name = obj.val; - })); + }); } for (var j = 0; j < sites.length; j++) { @@ -33,13 +35,17 @@ favorite: sites[j].favorite }); - promises.push(decrypt(sites[j].name, j).then(function (obj) { + var namePromise = decrypt(sites[j].name, j); + promises.push(namePromise); + namePromise.then(function (obj) { decSites[obj.index].name = obj.val; - })); + }); - promises.push(decrypt(sites[j].username, j).then(function (obj) { + var usernamePromise = decrypt(sites[j].username, j); + promises.push(usernamePromise); + usernamePromise.then(function (obj) { decSites[obj.index].username = obj.val; - })); + }); } $q.all(promises).then(function () { @@ -50,13 +56,19 @@ }); function decrypt(cipherString, index) { - return $q(function(resolve, reject) { + return $q(function (resolve, reject) { if (!cipherString) { - resolve({val: null, index: index}); + resolve({ + val: null, + index: index + }); } else { cipherString.decrypt(function (decString) { - resolve({ val: decString, index: index }); + resolve({ + val: decString, + index: index + }); }); } });