diff --git a/src/Vault/wwwroot/_references.js b/src/Vault/wwwroot/_references.js index b8efe7cb73..4e73814123 100644 --- a/src/Vault/wwwroot/_references.js +++ b/src/Vault/wwwroot/_references.js @@ -24,6 +24,7 @@ /// /// /// +/// /// /// /// diff --git a/src/Vault/wwwroot/app/services/importService.js b/src/Vault/wwwroot/app/services/importService.js new file mode 100644 index 0000000000..22bedbce76 --- /dev/null +++ b/src/Vault/wwwroot/app/services/importService.js @@ -0,0 +1,134 @@ +angular + .module('bit.services') + + .factory('importService', function () { + var _service = {}; + + _service.import = function (source, file, success, error) { + switch (source) { + case 'local': + importLocal(file, success, error); + break; + case 'lastpass': + importLastPass(file, success, error); + break; + default: + error(); + break; + } + }; + + function importLocal(file, success, error) { + Papa.parse(file, { + header: true, + complete: function (results) { + var folders = [], + sites = [], + siteRelationships = []; + + angular.forEach(results.data, function (value, key) { + if (!value.uri || value.uri === '') { + return; + } + + var folderIndex = folders.length, + siteIndex = sites.length, + hasFolder = value.folder && value.folder !== '', + addFolder = hasFolder; + + if (hasFolder) { + for (var i = 0; i < folders.length; i++) { + if (folders[i].name == value.folder) { + addFolder = false; + folderIndex = i; + break; + } + } + } + + sites.push({ + uri: value.uri, + username: value.username && value.username !== '' ? value.username : null, + password: value.password, + notes: value.notes && value.notes !== '' ? value.notes : null, + name: value.name + }); + + if (addFolder) { + folders.push({ + name: value.folder + }); + } + + if (hasFolder) { + var relationship = { + key: siteIndex, + value: folderIndex + }; + siteRelationships.push(relationship); + } + }); + + success(folders, sites, siteRelationships); + } + }); + } + + function importLastPass(file, success, error) { + Papa.parse(file, { + header: true, + complete: function (results) { + var folders = [], + sites = [], + siteRelationships = []; + + angular.forEach(results.data, function (value, key) { + if (!value.url || value.url === '') { + return; + } + + var folderIndex = folders.length, + siteIndex = sites.length, + hasFolder = value.grouping && value.grouping !== '' && value.grouping != '(none)', + addFolder = hasFolder; + + if (hasFolder) { + for (var i = 0; i < folders.length; i++) { + if (folders[i].name == value.grouping) { + addFolder = false; + folderIndex = i; + break; + } + } + } + + sites.push({ + uri: value.url, + username: value.username && value.username !== '' ? value.username : null, + password: value.password, + notes: value.extra && value.extra !== '' ? value.extra : null, + name: value.name + }); + + if (addFolder) { + folders.push({ + name: value.grouping + }); + } + + if (hasFolder) { + var relationship = { + key: siteIndex, + value: folderIndex + }; + siteRelationships.push(relationship); + } + }); + + success(folders, sites, siteRelationships); + } + }); + } + + return _service; + }); diff --git a/src/Vault/wwwroot/app/services/validationService.js b/src/Vault/wwwroot/app/services/validationService.js index d328948fb2..a724f5ebec 100644 --- a/src/Vault/wwwroot/app/services/validationService.js +++ b/src/Vault/wwwroot/app/services/validationService.js @@ -58,6 +58,5 @@ } }; - return _service; }); diff --git a/src/Vault/wwwroot/app/settings/views/settingsDelete.html b/src/Vault/wwwroot/app/settings/views/settingsDelete.html index 7b3212623d..b79cc80e30 100644 --- a/src/Vault/wwwroot/app/settings/views/settingsDelete.html +++ b/src/Vault/wwwroot/app/settings/views/settingsDelete.html @@ -1,6 +1,6 @@