From 9918e903b2ce1a74a11efcb95ec33d58420ffcce Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 19 May 2017 14:10:21 -0400 Subject: [PATCH] add support for passkeep csv import --- src/app/services/importService.js | 82 ++++++++++++++++++++++++++ src/app/tools/toolsImportController.js | 6 ++ 2 files changed, 88 insertions(+) diff --git a/src/app/services/importService.js b/src/app/services/importService.js index 96fa1bd5f6..55a35b38f7 100644 --- a/src/app/services/importService.js +++ b/src/app/services/importService.js @@ -95,6 +95,9 @@ case 'meldiumcsv': importMeldiumCsv(file, success, error); break; + case 'passkeepcsv': + importPassKeepCsv(file, success, error); + break; default: error(); break; @@ -2369,5 +2372,84 @@ }); } + function importPassKeepCsv(file, success, error) { + function getValue(key, obj) { + var val = obj[key] || obj[(' ' + key)]; + if (val && val !== '') { + return val; + } + + return null; + } + + Papa.parse(file, { + header: true, + encoding: 'UTF-8', + complete: function (results) { + parseCsvErrors(results); + + var folders = [], + logins = [], + folderRelationships = []; + + angular.forEach(results.data, function (value, key) { + var folderIndex = folders.length, + loginIndex = logins.length, + hasFolder = !!getValue('category', value), + addFolder = hasFolder, + i = 0; + + if (hasFolder) { + for (i = 0; i < folders.length; i++) { + if (folders[i].name === getValue('category', value)) { + addFolder = false; + folderIndex = i; + break; + } + } + } + + var login = { + favorite: false, + uri: !!getValue('site', value) ? fixUri(getValue('site', value)) : null, + username: !!getValue('username', value) ? getValue('username', value) : null, + password: !!getValue('password', value) ? getValue('password', value) : null, + notes: !!getValue('description', value) ? getValue('description', value) : null, + name: !!getValue('title', value) ? getValue('title', value) : '--' + }; + + if (!!getValue('password2', value)) { + if (!login.notes) { + login.notes = ''; + } + else { + login.notes += '\n'; + } + + login.notes += ('Password 2: ' + getValue('password2', value)); + } + + logins.push(login); + + if (addFolder) { + folders.push({ + name: getValue('category', value) + }); + } + + if (hasFolder) { + var relationship = { + key: loginIndex, + value: folderIndex + }; + folderRelationships.push(relationship); + } + }); + + success(folders, logins, folderRelationships); + } + }); + } + return _service; }); diff --git a/src/app/tools/toolsImportController.js b/src/app/tools/toolsImportController.js index a44e98bd62..0e7ac276c9 100644 --- a/src/app/tools/toolsImportController.js +++ b/src/app/tools/toolsImportController.js @@ -196,6 +196,12 @@ name: 'Meldium (csv)', instructions: $sce.trustAsHtml('Using the Meldium web vault, navigate to "Settings". ' + 'Locate the "Export data" function and click "Show me my data" to save the CSV file.') + }, + { + id: 'passkeepcsv', + name: 'PassKeep (csv)', + instructions: $sce.trustAsHtml('Using the PassKeep mobile app, navigate to "Backup/Restore". ' + + 'Locate the "CSV Backup/Restore" section and click "Backup to CSV" to save the CSV file.') } ];