1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

login custom fields view/edit

This commit is contained in:
Kyle Spearrin
2017-09-21 22:45:24 -04:00
parent 56e1f6c25b
commit 835bb6ffa7
13 changed files with 255 additions and 50 deletions

View File

@@ -18,6 +18,17 @@
default:
break;
}
if (cipher.fields) {
this.fields = [];
for (var i = 0; i < cipher.fields.length; i++) {
this.fields.push({
type: cipher.fields[i].type,
name: cipher.fields[i].name ? cipher.fields[i].name.encryptedString : null,
value: cipher.fields[i].value ? cipher.fields[i].value.encryptedString : null,
});
}
}
};
var FolderRequest = function (folder) {

View File

@@ -145,16 +145,17 @@ var SyncResponse = function (response) {
this.profile = new ProfileResponse(response.Profile);
}
var i;
this.folders = [];
if (response.Folders) {
for (var i = 0; i < response.Folders.length; i++) {
for (i = 0; i < response.Folders.length; i++) {
this.folders.push(new FolderResponse(response.Folders[i]));
}
}
this.ciphers = [];
if (response.Ciphers) {
for (var i = 0; i < response.Ciphers.length; i++) {
for (i = 0; i < response.Ciphers.length; i++) {
this.ciphers.push(new CipherResponse(response.Ciphers[i]));
}
}

View File

@@ -31,9 +31,17 @@ var LoginData = function (response, userId) {
this.favorite = response.favorite;
this.revisionDate = response.revisionDate;
var i;
if (response.data.Fields) {
this.fields = [];
for (i = 0; i < response.data.Fields.length; i++) {
this.fields.push(new FieldData(response.data.Fields[i]));
}
}
if (response.attachments) {
this.attachments = [];
for (var i = 0; i < response.attachments.length; i++) {
for (i = 0; i < response.attachments.length; i++) {
this.attachments.push(new AttachmentData(response.attachments[i]));
}
}
@@ -46,3 +54,9 @@ var AttachmentData = function (response) {
this.size = response.size;
this.sizeName = response.sizeName;
};
var FieldData = function (response) {
this.type = response.Type;
this.name = response.Name;
this.value = response.Value;
};

View File

@@ -114,15 +114,39 @@ var Login = function (obj, alreadyEncrypted, localData) {
this.totp = obj.totp ? new CipherString(obj.totp) : null;
}
var i;
if (obj.attachments) {
this.attachments = [];
for (var i = 0; i < obj.attachments.length; i++) {
for (i = 0; i < obj.attachments.length; i++) {
this.attachments.push(new Attachment(obj.attachments[i], alreadyEncrypted));
}
}
else {
this.attachments = null;
}
if (obj.fields) {
this.fields = [];
for (i = 0; i < obj.fields.length; i++) {
this.fields.push(new Field(obj.fields[i], alreadyEncrypted));
}
}
else {
this.fields = null;
}
};
var Field = function (obj, alreadyEncrypted) {
this.type = obj.type;
if (alreadyEncrypted === true) {
this.name = obj.name ? obj.name : null;
this.value = obj.value ? obj.value : null;
}
else {
this.name = obj.name ? new CipherString(obj.name) : null;
this.value = obj.value ? new CipherString(obj.value) : null;
}
};
var Attachment = function (obj, alreadyEncrypted) {
@@ -182,9 +206,9 @@ var Folder = function (obj, alreadyEncrypted) {
};
var attachments = [];
var deferred = Q.defer();
var fields = [];
self.name.decrypt(self.organizationId).then(function (val) {
return self.name.decrypt(self.organizationId).then(function (val) {
model.name = val;
if (self.uri) {
return self.uri.decrypt(self.organizationId);
@@ -222,24 +246,58 @@ var Folder = function (obj, alreadyEncrypted) {
model.totp = val;
if (self.attachments) {
var attachmentPromises = [];
for (var i = 0; i < self.attachments.length; i++) {
(function (attachment) {
var promise = attachment.decrypt(self.organizationId).then(function (decAttachment) {
attachments.push(decAttachment);
});
attachmentPromises.push(promise);
})(self.attachments[i]);
}
return Q.all(attachmentPromises);
return self.attachments.reduce(function (promise, attachment) {
return promise.then(function () {
return attachment.decrypt(self.organizationId);
}).then(function (decAttachment) {
attachments.push(decAttachment);
});
}, Q());
}
return;
}).then(function () {
model.attachments = attachments.length ? attachments : null;
deferred.resolve(model);
});
return deferred.promise;
if (self.fields) {
return self.fields.reduce(function (promise, field) {
return promise.then(function () {
return field.decrypt(self.organizationId);
}).then(function (decField) {
fields.push(decField);
});
}, Q());
}
return;
}).then(function () {
model.fields = fields.length ? fields : null;
return model;
}, function (e) {
console.log(e);
});
};
Field.prototype.decrypt = function (orgId) {
var self = this;
var model = {
type: self.type
};
return Q().then(function () {
if (self.name) {
return self.name.decrypt(orgId);
}
return null;
}).then(function (val) {
model.name = val;
if (self.value) {
return self.value.decrypt(orgId);
}
return null;
}).then(function (val) {
model.value = val;
return model;
});
};
Attachment.prototype.decrypt = function (orgId) {
@@ -251,14 +309,10 @@ var Folder = function (obj, alreadyEncrypted) {
url: self.url
};
var deferred = Q.defer();
self.fileName.decrypt(orgId).then(function (val) {
return self.fileName.decrypt(orgId).then(function (val) {
model.fileName = val;
deferred.resolve(model);
return model;
});
return deferred.promise;
};
Folder.prototype.decrypt = function () {
@@ -267,13 +321,9 @@ var Folder = function (obj, alreadyEncrypted) {
id: self.id
};
var deferred = Q.defer();
self.name.decrypt().then(function (val) {
return self.name.decrypt().then(function (val) {
model.name = val;
deferred.resolve(model);
return model;
});
return deferred.promise;
};
})();