1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

build models for cipher types

This commit is contained in:
Kyle Spearrin
2017-10-13 14:04:03 -04:00
parent e482ace0f7
commit 44f5812a36
3 changed files with 392 additions and 60 deletions

View File

@@ -15,6 +15,7 @@ var FolderData = function (response, userId) {
this.revisionDate = response.revisionDate;
};
// deprecated
var LoginData = function (response, userId) {
this.id = response.id;
this.organizationId = response.organizationId;
@@ -47,6 +48,53 @@ var LoginData = function (response, userId) {
}
};
var CipherData = function (response, userId) {
this.id = response.id;
this.organizationId = response.organizationId;
this.folderId = response.folderId;
this.userId = userId;
this.edit = response.edit;
this.organizationUseTotp = response.organizationUseTotp;
this.favorite = response.favorite;
this.revisionDate = response.revisionDate;
this.type = response.type;
this.name = response.data.Name;
this.notes = response.notes = response.data.Notes;
switch (this.type) {
case 1: // cipherType.login
this.login = new LoginData2(response.data);
break;
case 2: // cipherType.secureNote
this.secureNote = new SecureNoteData(response.data);
break;
case 3: // cipherType.card
this.card = new CardData(response.data);
break;
case 4: // cipherType.identity
this.identity = new IdentityData(response.data);
break;
default:
break;
}
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 (i = 0; i < response.attachments.length; i++) {
this.attachments.push(new AttachmentData(response.attachments[i]));
}
}
};
var AttachmentData = function (response) {
this.id = response.id;
this.url = response.url;
@@ -60,3 +108,44 @@ var FieldData = function (response) {
this.name = response.Name;
this.value = response.Value;
};
var LoginData2 = function (data) {
this.uri = data.Uri;
this.username = data.Username;
this.password = data.Password;
this.totp = data.Totp;
};
var IdentityData = function (data) {
this.title = data.Title;
this.firstName = data.FirstName;
this.middleName = data.MiddleName;
this.lastName = data.LastName;
this.address1 = data.Address1;
this.address2 = data.Address2;
this.address3 = data.Address3;
this.city = data.City;
this.state = data.State;
this.postalCode = data.PostalCode;
this.country = data.Country;
this.company = data.Company;
this.email = data.Email;
this.phone = data.Phone;
this.ssn = data.SSN;
this.username = data.Username;
this.passportNumber = data.PassportNumber;
this.licenseNumber = data.LicenseNumber;
};
var SecureNoteData = function (data) {
this.type = data.Type;
};
var CardData = function (data) {
this.cardholderName = data.CardholderName;
this.brand = data.Brand;
this.number = data.Number;
this.expMonth = data.ExpMonth;
this.expYear = data.ExpYear;
this.code = data.Code;
};