import/export custom fields

This commit is contained in:
Kyle Spearrin 2017-10-02 12:37:17 -04:00
parent c7802940b1
commit 21635dd728
2 changed files with 52 additions and 5 deletions

View File

@ -243,7 +243,8 @@
var folders = [], var folders = [],
logins = [], logins = [],
folderRelationships = []; folderRelationships = [],
i = 0;
angular.forEach(results.data, function (value, key) { angular.forEach(results.data, function (value, key) {
var folderIndex = folders.length, var folderIndex = folders.length,
@ -252,7 +253,7 @@
addFolder = hasFolder; addFolder = hasFolder;
if (hasFolder) { if (hasFolder) {
for (var i = 0; i < folders.length; i++) { for (i = 0; i < folders.length; i++) {
if (folders[i].name === value.folder) { if (folders[i].name === value.folder) {
addFolder = false; addFolder = false;
folderIndex = i; folderIndex = i;
@ -261,7 +262,7 @@
} }
} }
logins.push({ var login = {
favorite: value.favorite && value.favorite !== '' && value.favorite !== '0' ? true : false, favorite: value.favorite && value.favorite !== '' && value.favorite !== '0' ? true : false,
uri: value.uri && value.uri !== '' ? trimUri(value.uri) : null, uri: value.uri && value.uri !== '' ? trimUri(value.uri) : null,
username: value.username && value.username !== '' ? value.username : null, username: value.username && value.username !== '' ? value.username : null,
@ -269,7 +270,39 @@
notes: value.notes && value.notes !== '' ? value.notes : null, notes: value.notes && value.notes !== '' ? value.notes : null,
name: value.name && value.name !== '' ? value.name : '--', name: value.name && value.name !== '' ? value.name : '--',
totp: value.totp && value.totp !== '' ? value.totp : null totp: value.totp && value.totp !== '' ? value.totp : null
}); };
if (value.fields && value.fields !== '') {
var fields = value.fields.split('\n');
for (i = 0; i < fields.length; i++) {
if (!fields[i] || fields[i] === '') {
continue;
}
var delimPosition = fields[i].lastIndexOf(': ');
if (delimPosition === -1) {
continue;
}
if (!login.fields) {
login.fields = [];
}
var field = {
name: fields[i].substr(0, delimPosition),
value: null,
type: 0
}
if (fields[i].length > (delimPosition + 2)) {
field.value = fields[i].substr(delimPosition + 2);
}
login.fields.push(field);
}
}
logins.push(login);
if (addFolder) { if (addFolder) {
folders.push({ folders.push({

View File

@ -41,9 +41,23 @@
folder: decLogins[i].folderId && (decLogins[i].folderId in foldersDict) ? folder: decLogins[i].folderId && (decLogins[i].folderId in foldersDict) ?
foldersDict[decLogins[i].folderId].name : null, foldersDict[decLogins[i].folderId].name : null,
favorite: decLogins[i].favorite ? 1 : null, favorite: decLogins[i].favorite ? 1 : null,
totp: decLogins[i].totp totp: decLogins[i].totp,
fields: null
}; };
if (decLogins[i].fields) {
for (var j = 0; j < decLogins[i].fields.length; j++) {
if (!login.fields) {
login.fields = '';
}
else {
login.fields += '\n';
}
login.fields += (decLogins[i].fields[j].name + ': ' + decLogins[i].fields[j].value);
}
}
exportLogins.push(login); exportLogins.push(login);
} }