diff --git a/src/Core/Enums/CipherType.cs b/src/Core/Enums/CipherType.cs index c44c011398..0aca948640 100644 --- a/src/Core/Enums/CipherType.cs +++ b/src/Core/Enums/CipherType.cs @@ -3,9 +3,10 @@ public enum CipherType : byte { // Folder is deprecated - Folder = 0, + //Folder = 0, Login = 1, SecureNote = 2, - Card = 3 + Card = 3, + Identity = 4 } } diff --git a/src/Core/Models/Api/IdentityDataModel.cs b/src/Core/Models/Api/IdentityDataModel.cs new file mode 100644 index 0000000000..f7e4f3e52d --- /dev/null +++ b/src/Core/Models/Api/IdentityDataModel.cs @@ -0,0 +1,80 @@ +using System; +using Bit.Core.Models.Table; +using Newtonsoft.Json; + +namespace Bit.Core.Models.Api +{ + public class IdentityDataModel : CipherDataModel + { + public IdentityDataModel() { } + + public IdentityDataModel(CipherRequestModel cipher) + { + Name = cipher.Name; + Notes = cipher.Notes; + Fields = cipher.Fields; + + Title = cipher.Identity.Title; + FirstName = cipher.Identity.FirstName; + MiddleName = cipher.Identity.MiddleName; + LastName = cipher.Identity.LastName; + Address1 = cipher.Identity.Address1; + Address2 = cipher.Identity.Address2; + Address3 = cipher.Identity.Address3; + City = cipher.Identity.City; + State = cipher.Identity.City; + PostalCode = cipher.Identity.PostalCode; + Country = cipher.Identity.Country; + Company = cipher.Identity.Company; + Email = cipher.Identity.Email; + Phone = cipher.Identity.Phone; + SSN = cipher.Identity.SSN; + } + + public IdentityDataModel(Cipher cipher) + { + if(cipher.Type != Enums.CipherType.Identity) + { + throw new ArgumentException("Cipher is not correct type."); + } + + var data = JsonConvert.DeserializeObject(cipher.Data); + + Name = data.Name; + Notes = data.Notes; + Fields = data.Fields; + + Title = data.Title; + FirstName = data.FirstName; + MiddleName = data.MiddleName; + LastName = data.LastName; + Address1 = data.Address1; + Address2 = data.Address2; + Address3 = data.Address3; + City = data.City; + State = data.State; + PostalCode = data.PostalCode; + Country = data.Country; + Company = data.Company; + Email = data.Email; + Phone = data.Phone; + SSN = data.SSN; + } + + public string Title { get; set; } + public string FirstName { get; set; } + public string MiddleName { get; set; } + public string LastName { get; set; } + public string Address1 { get; set; } + public string Address2 { get; set; } + public string Address3 { get; set; } + public string City { get; set; } + public string State { get; set; } + public string PostalCode { get; set; } + public string Country { get; set; } + public string Company { get; set; } + public string Email { get; set; } + public string Phone { get; set; } + public string SSN { get; set; } + } +} diff --git a/src/Core/Models/Api/Request/CipherRequestModel.cs b/src/Core/Models/Api/Request/CipherRequestModel.cs index cf5e045c74..6fa7172b00 100644 --- a/src/Core/Models/Api/Request/CipherRequestModel.cs +++ b/src/Core/Models/Api/Request/CipherRequestModel.cs @@ -30,6 +30,7 @@ namespace Bit.Core.Models.Api public LoginType Login { get; set; } public CardType Card { get; set; } + public IdentityType Identity { get; set; } public SecureNoteType SecureNote { get; set; } public CipherDetails ToCipherDetails(Guid userId) @@ -65,12 +66,16 @@ namespace Bit.Core.Models.Api existingCipher.Data = JsonConvert.SerializeObject(new CardDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); break; + case CipherType.Identity: + existingCipher.Data = JsonConvert.SerializeObject(new IdentityDataModel(this), + new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); + break; case CipherType.SecureNote: existingCipher.Data = JsonConvert.SerializeObject(new SecureNoteDataModel(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); break; default: - throw new ArgumentException("Unsupported " + nameof(Type) + "."); + throw new ArgumentException("Unsupported type: " + nameof(Type) + "."); } if((Attachments?.Count ?? 0) == 0) @@ -155,6 +160,55 @@ namespace Bit.Core.Models.Api public string Code { get; set; } } + public class IdentityType + { + [EncryptedString] + [StringLength(1000)] + public string Title { get; set; } + [EncryptedString] + [StringLength(1000)] + public string FirstName { get; set; } + [EncryptedString] + [StringLength(1000)] + public string MiddleName { get; set; } + [EncryptedString] + [StringLength(1000)] + public string LastName { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Address1 { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Address2 { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Address3 { get; set; } + [EncryptedString] + [StringLength(1000)] + public string City { get; set; } + [EncryptedString] + [StringLength(1000)] + public string State { get; set; } + [EncryptedString] + [StringLength(1000)] + public string PostalCode { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Country { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Company { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Email { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Phone { get; set; } + [EncryptedString] + [StringLength(1000)] + public string SSN { get; set; } + } + public class SecureNoteType { public Enums.SecureNoteType Type { get; set; }