diff --git a/src/Core/Enums/UriMatchType.cs b/src/Core/Enums/UriMatchType.cs new file mode 100644 index 0000000000..ac3f278fa1 --- /dev/null +++ b/src/Core/Enums/UriMatchType.cs @@ -0,0 +1,11 @@ +namespace Bit.Core.Enums +{ + public enum UriMatchType : byte + { + BaseDomain = 0, + FullHostname = 1, + FullUri = 2, + StartsWith = 3, + RegularExpression = 4 + } +} diff --git a/src/Core/Models/Api/CardDataModel.cs b/src/Core/Models/Api/CardDataModel.cs deleted file mode 100644 index b45e056036..0000000000 --- a/src/Core/Models/Api/CardDataModel.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using Bit.Core.Models.Table; -using Newtonsoft.Json; - -namespace Bit.Core.Models.Api -{ - public class CardDataModel : CipherDataModel - { - public CardDataModel() { } - - public CardDataModel(CipherRequestModel cipher) - { - Name = cipher.Name; - Notes = cipher.Notes; - Fields = cipher.Fields; - - CardholderName = cipher.Card.CardholderName; - Brand = cipher.Card.Brand; - Number = cipher.Card.Number; - ExpMonth = cipher.Card.ExpMonth; - ExpYear = cipher.Card.ExpYear; - Code = cipher.Card.Code; - } - - public CardDataModel(Cipher cipher) - { - if(cipher.Type != Enums.CipherType.Card) - { - throw new ArgumentException("Cipher is not correct type."); - } - - var data = JsonConvert.DeserializeObject(cipher.Data); - - Name = data.Name; - Notes = data.Notes; - Fields = data.Fields; - - CardholderName = data.CardholderName; - Brand = data.Brand; - Number = data.Number; - ExpMonth = data.ExpMonth; - ExpYear = data.ExpYear; - Code = data.Code; - } - - public string CardholderName { get; set; } - public string Brand { get; set; } - public string Number { get; set; } - public string ExpMonth { get; set; } - public string ExpYear { get; set; } - public string Code { get; set; } - } -} diff --git a/src/Core/Models/Api/CipherCardModel.cs b/src/Core/Models/Api/CipherCardModel.cs new file mode 100644 index 0000000000..9a928df10d --- /dev/null +++ b/src/Core/Models/Api/CipherCardModel.cs @@ -0,0 +1,40 @@ +using System.ComponentModel.DataAnnotations; +using Bit.Core.Models.Data; +using Bit.Core.Utilities; + +namespace Bit.Core.Models.Api +{ + public class CipherCardModel + { + public CipherCardModel() { } + + public CipherCardModel(CipherCardData data) + { + CardholderName = data.CardholderName; + Brand = data.Brand; + Number = data.Number; + ExpMonth = data.ExpMonth; + ExpYear = data.ExpYear; + Code = data.Code; + } + + [EncryptedString] + [StringLength(1000)] + public string CardholderName { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Brand { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Number { get; set; } + [EncryptedString] + [StringLength(1000)] + public string ExpMonth { get; set; } + [EncryptedString] + [StringLength(1000)] + public string ExpYear { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Code { get; set; } + } +} diff --git a/src/Core/Models/Api/CipherDataModel.cs b/src/Core/Models/Api/CipherDataModel.cs deleted file mode 100644 index 9e7b55d1e4..0000000000 --- a/src/Core/Models/Api/CipherDataModel.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; - -namespace Bit.Core.Models.Api -{ - public abstract class CipherDataModel - { - public string Name { get; set; } - public string Notes { get; set; } - public IEnumerable Fields { get; set; } - } -} diff --git a/src/Core/Models/Api/FieldDataModel.cs b/src/Core/Models/Api/CipherFieldModel.cs similarity index 56% rename from src/Core/Models/Api/FieldDataModel.cs rename to src/Core/Models/Api/CipherFieldModel.cs index f3ec4bc627..f703bd3931 100644 --- a/src/Core/Models/Api/FieldDataModel.cs +++ b/src/Core/Models/Api/CipherFieldModel.cs @@ -1,10 +1,18 @@ using System.ComponentModel.DataAnnotations; using Bit.Core.Enums; +using Bit.Core.Models.Data; namespace Bit.Core.Models.Api { - public class FieldDataModel + public class CipherFieldModel { + public CipherFieldModel(CipherFieldData data) + { + Type = data.Type; + Name = data.Name; + Value = data.Value; + } + public FieldType Type { get; set; } [StringLength(1000)] public string Name { get; set; } diff --git a/src/Core/Models/Api/CipherIdentityModel.cs b/src/Core/Models/Api/CipherIdentityModel.cs new file mode 100644 index 0000000000..3e4afb69d6 --- /dev/null +++ b/src/Core/Models/Api/CipherIdentityModel.cs @@ -0,0 +1,88 @@ +using System.ComponentModel.DataAnnotations; +using Bit.Core.Models.Data; +using Bit.Core.Utilities; + +namespace Bit.Core.Models.Api +{ + public class CipherIdentityModel + { + public CipherIdentityModel() { } + + public CipherIdentityModel(CipherIdentityData data) + { + 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; + Username = data.Username; + PassportNumber = data.PassportNumber; + LicenseNumber = data.LicenseNumber; + } + + [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; } + [EncryptedString] + [StringLength(1000)] + public string Username { get; set; } + [EncryptedString] + [StringLength(1000)] + public string PassportNumber { get; set; } + [EncryptedString] + [StringLength(1000)] + public string LicenseNumber { get; set; } + } +} diff --git a/src/Core/Models/Api/CipherLoginModel.cs b/src/Core/Models/Api/CipherLoginModel.cs new file mode 100644 index 0000000000..144cc7d43c --- /dev/null +++ b/src/Core/Models/Api/CipherLoginModel.cs @@ -0,0 +1,68 @@ +using System.ComponentModel.DataAnnotations; +using Bit.Core.Utilities; +using Bit.Core.Enums; +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Models.Data; + +namespace Bit.Core.Models.Api +{ + public class CipherLoginModel + { + public CipherLoginModel(CipherLoginData data) + { + Uris = data.Uris.Select(u => new LoginApiUriModel(u)); + Username = data.Username; + Password = data.Password; + Totp = data.Totp; + } + + [EncryptedString] + [StringLength(10000)] + public string Uri + { + get => Uris?.FirstOrDefault()?.Uri; + set + { + if(Uris == null) + { + Uris = new List(); + } + + Uris.Append(new LoginApiUriModel(value)); + } + } + public IEnumerable Uris { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Username { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Password { get; set; } + [EncryptedString] + [StringLength(1000)] + public string Totp { get; set; } + + public class LoginApiUriModel + { + public LoginApiUriModel() { } + + public LoginApiUriModel(string uri) + { + Uri = uri; + MatchType = UriMatchType.BaseDomain; + } + + public LoginApiUriModel(CipherLoginData.LoginDataUriModel uri) + { + Uri = uri.Uri; + MatchType = uri.MatchType; + } + + [EncryptedString] + [StringLength(10000)] + public string Uri { get; set; } + public UriMatchType MatchType { get; set; } + } + } +} diff --git a/src/Core/Models/Api/CipherSecureNoteModel.cs b/src/Core/Models/Api/CipherSecureNoteModel.cs new file mode 100644 index 0000000000..8ba51d83b8 --- /dev/null +++ b/src/Core/Models/Api/CipherSecureNoteModel.cs @@ -0,0 +1,15 @@ +using Bit.Core.Enums; +using Bit.Core.Models.Data; + +namespace Bit.Core.Models.Api +{ + public class CipherSecureNoteModel + { + public SecureNoteType Type { get; set; } + + public CipherSecureNoteModel(CipherSecureNoteData data) + { + Type = data.Type; + } + } +} diff --git a/src/Core/Models/Api/LoginDataModel.cs b/src/Core/Models/Api/LoginDataModel.cs deleted file mode 100644 index 354adeeb60..0000000000 --- a/src/Core/Models/Api/LoginDataModel.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using Bit.Core.Models.Table; -using Newtonsoft.Json; - -namespace Bit.Core.Models.Api -{ - public class LoginDataModel : CipherDataModel - { - public LoginDataModel() { } - - public LoginDataModel(CipherRequestModel cipher) - { - Name = cipher.Name; - Notes = cipher.Notes; - Fields = cipher.Fields; - - Uri = cipher.Login.Uri; - Username = cipher.Login.Username; - Password = cipher.Login.Password; - Totp = cipher.Login.Totp; - } - - public LoginDataModel(Cipher cipher) - { - if(cipher.Type != Enums.CipherType.Login) - { - throw new ArgumentException("Cipher is not correct type."); - } - - var data = JsonConvert.DeserializeObject(cipher.Data); - - Name = data.Name; - Notes = data.Notes; - Fields = data.Fields; - - Uri = data.Uri; - Username = data.Username; - Password = data.Password; - Totp = data.Totp; - } - - public string Uri { get; set; } - public string Username { get; set; } - public string Password { get; set; } - public string Totp { get; set; } - } -} diff --git a/src/Core/Models/Api/Request/CipherRequestModel.cs b/src/Core/Models/Api/Request/CipherRequestModel.cs index e9e395e710..b4489ad025 100644 --- a/src/Core/Models/Api/Request/CipherRequestModel.cs +++ b/src/Core/Models/Api/Request/CipherRequestModel.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; using Core.Models.Data; +using Bit.Core.Models.Data; namespace Bit.Core.Models.Api { @@ -25,13 +26,13 @@ namespace Bit.Core.Models.Api [EncryptedString] [StringLength(10000)] public string Notes { get; set; } - public IEnumerable Fields { get; set; } + public IEnumerable Fields { get; set; } public Dictionary Attachments { get; set; } - public LoginType Login { get; set; } - public CardType Card { get; set; } - public IdentityType Identity { get; set; } - public SecureNoteType SecureNote { get; set; } + public CipherLoginModel Login { get; set; } + public CipherCardModel Card { get; set; } + public CipherIdentityModel Identity { get; set; } + public CipherSecureNoteModel SecureNote { get; set; } public CipherDetails ToCipherDetails(Guid userId) { @@ -59,19 +60,19 @@ namespace Bit.Core.Models.Api switch(existingCipher.Type) { case CipherType.Login: - existingCipher.Data = JsonConvert.SerializeObject(new LoginDataModel(this), + existingCipher.Data = JsonConvert.SerializeObject(new CipherLoginData(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); break; case CipherType.Card: - existingCipher.Data = JsonConvert.SerializeObject(new CardDataModel(this), + existingCipher.Data = JsonConvert.SerializeObject(new CipherCardData(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); break; case CipherType.Identity: - existingCipher.Data = JsonConvert.SerializeObject(new IdentityDataModel(this), + existingCipher.Data = JsonConvert.SerializeObject(new CipherIdentityData(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); break; case CipherType.SecureNote: - existingCipher.Data = JsonConvert.SerializeObject(new SecureNoteDataModel(this), + existingCipher.Data = JsonConvert.SerializeObject(new CipherSecureNoteData(this), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); break; default: @@ -121,107 +122,6 @@ namespace Bit.Core.Models.Api Edit = true }); } - - public class LoginType - { - [EncryptedString] - [StringLength(10000)] - public string Uri { get; set; } - [EncryptedString] - [StringLength(1000)] - public string Username { get; set; } - [EncryptedString] - [StringLength(1000)] - public string Password { get; set; } - [EncryptedString] - [StringLength(1000)] - public string Totp { get; set; } - } - - public class CardType - { - [EncryptedString] - [StringLength(1000)] - public string CardholderName { get; set; } - [EncryptedString] - [StringLength(1000)] - public string Brand { get; set; } - [EncryptedString] - [StringLength(1000)] - public string Number { get; set; } - [EncryptedString] - [StringLength(1000)] - public string ExpMonth { get; set; } - [EncryptedString] - [StringLength(1000)] - public string ExpYear { get; set; } - [EncryptedString] - [StringLength(1000)] - 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; } - [EncryptedString] - [StringLength(1000)] - public string Username { get; set; } - [EncryptedString] - [StringLength(1000)] - public string PassportNumber { get; set; } - [EncryptedString] - [StringLength(1000)] - public string LicenseNumber { get; set; } - } - - public class SecureNoteType - { - public Enums.SecureNoteType Type { get; set; } - } } public class CipherWithIdRequestModel : CipherRequestModel diff --git a/src/Core/Models/Api/Response/CipherResponseModel.cs b/src/Core/Models/Api/Response/CipherResponseModel.cs index 4850c5dec3..10cbe1f733 100644 --- a/src/Core/Models/Api/Response/CipherResponseModel.cs +++ b/src/Core/Models/Api/Response/CipherResponseModel.cs @@ -3,6 +3,8 @@ using Core.Models.Data; using System.Collections.Generic; using Bit.Core.Models.Table; using System.Linq; +using Newtonsoft.Json; +using Bit.Core.Models.Data; namespace Bit.Core.Models.Api { @@ -18,34 +20,58 @@ namespace Bit.Core.Models.Api Id = cipher.Id.ToString(); Type = cipher.Type; - RevisionDate = cipher.RevisionDate; - OrganizationId = cipher.OrganizationId?.ToString(); - Attachments = AttachmentResponseModel.FromCipher(cipher, globalSettings); - OrganizationUseTotp = orgUseTotp; + CipherData cipherData; switch(cipher.Type) { case Enums.CipherType.Login: - Data = new LoginDataModel(cipher); + var loginData = JsonConvert.DeserializeObject(cipher.Data); + cipherData = loginData; + Data = loginData; + Login = new CipherLoginModel(loginData); break; case Enums.CipherType.SecureNote: - Data = new SecureNoteDataModel(cipher); + var secureNoteData = JsonConvert.DeserializeObject(cipher.Data); + Data = secureNoteData; + cipherData = secureNoteData; + SecureNote = new CipherSecureNoteModel(secureNoteData); break; case Enums.CipherType.Card: - Data = new CardDataModel(cipher); + var cardData = JsonConvert.DeserializeObject(cipher.Data); + Data = cardData; + cipherData = cardData; + Card = new CipherCardModel(cardData); break; case Enums.CipherType.Identity: - Data = new IdentityDataModel(cipher); + var identityData = JsonConvert.DeserializeObject(cipher.Data); + Data = identityData; + cipherData = identityData; + Identity = new CipherIdentityModel(identityData); break; default: throw new ArgumentException("Unsupported " + nameof(Type) + "."); } + + Name = cipherData.Name; + Notes = cipherData.Notes; + Fields = cipherData.Fields.Select(f => new CipherFieldModel(f)); + RevisionDate = cipher.RevisionDate; + OrganizationId = cipher.OrganizationId?.ToString(); + Attachments = AttachmentResponseModel.FromCipher(cipher, globalSettings); + OrganizationUseTotp = orgUseTotp; } public string Id { get; set; } public string OrganizationId { get; set; } public Enums.CipherType Type { get; set; } public dynamic Data { get; set; } + public string Name { get; set; } + public string Notes { get; set; } + public CipherLoginModel Login { get; set; } + public CipherCardModel Card { get; set; } + public CipherIdentityModel Identity { get; set; } + public CipherSecureNoteModel SecureNote { get; set; } + public IEnumerable Fields { get; set; } public IEnumerable Attachments { get; set; } public bool OrganizationUseTotp { get; set; } public DateTime RevisionDate { get; set; } diff --git a/src/Core/Models/Api/SecureNoteDataModel.cs b/src/Core/Models/Api/SecureNoteDataModel.cs deleted file mode 100644 index e3f66f31b9..0000000000 --- a/src/Core/Models/Api/SecureNoteDataModel.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using Bit.Core.Enums; -using Bit.Core.Models.Table; -using Newtonsoft.Json; - -namespace Bit.Core.Models.Api -{ - public class SecureNoteDataModel : CipherDataModel - { - public SecureNoteDataModel() { } - - public SecureNoteDataModel(CipherRequestModel cipher) - { - Name = cipher.Name; - Notes = cipher.Notes; - Fields = cipher.Fields; - - Type = cipher.SecureNote.Type; - } - - public SecureNoteDataModel(Cipher cipher) - { - if(cipher.Type != CipherType.SecureNote) - { - throw new ArgumentException("Cipher is not correct type."); - } - - var data = JsonConvert.DeserializeObject(cipher.Data); - - Name = data.Name; - Notes = data.Notes; - Fields = data.Fields; - - Type = data.Type; - } - - public SecureNoteType Type { get; set; } - } -} diff --git a/src/Core/Models/Data/CipherCardData.cs b/src/Core/Models/Data/CipherCardData.cs new file mode 100644 index 0000000000..5c85de812b --- /dev/null +++ b/src/Core/Models/Data/CipherCardData.cs @@ -0,0 +1,27 @@ +using Bit.Core.Models.Api; + +namespace Bit.Core.Models.Data +{ + public class CipherCardData : CipherData + { + public CipherCardData() { } + + public CipherCardData(CipherRequestModel cipher) + : base(cipher) + { + CardholderName = cipher.Card.CardholderName; + Brand = cipher.Card.Brand; + Number = cipher.Card.Number; + ExpMonth = cipher.Card.ExpMonth; + ExpYear = cipher.Card.ExpYear; + Code = cipher.Card.Code; + } + + public string CardholderName { get; set; } + public string Brand { get; set; } + public string Number { get; set; } + public string ExpMonth { get; set; } + public string ExpYear { get; set; } + public string Code { get; set; } + } +} diff --git a/src/Core/Models/Data/CipherData.cs b/src/Core/Models/Data/CipherData.cs new file mode 100644 index 0000000000..c12d68beea --- /dev/null +++ b/src/Core/Models/Data/CipherData.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Models.Api; + +namespace Bit.Core.Models.Data +{ + public abstract class CipherData + { + public CipherData() { } + + public CipherData(CipherRequestModel cipher) + { + Name = cipher.Name; + Notes = cipher.Notes; + Fields = cipher.Fields.Select(f => new CipherFieldData(f)); + } + + public string Name { get; set; } + public string Notes { get; set; } + public IEnumerable Fields { get; set; } + } +} diff --git a/src/Core/Models/Data/CipherFieldData.cs b/src/Core/Models/Data/CipherFieldData.cs new file mode 100644 index 0000000000..8aa91f685b --- /dev/null +++ b/src/Core/Models/Data/CipherFieldData.cs @@ -0,0 +1,21 @@ +using Bit.Core.Enums; +using Bit.Core.Models.Api; + +namespace Bit.Core.Models.Data +{ + public class CipherFieldData + { + public CipherFieldData() { } + + public CipherFieldData(CipherFieldModel field) + { + Type = field.Type; + Name = field.Name; + Value = field.Value; + } + + public FieldType Type { get; set; } + public string Name { get; set; } + public string Value { get; set; } + } +} diff --git a/src/Core/Models/Api/IdentityDataModel.cs b/src/Core/Models/Data/CipherIdentityData.cs similarity index 54% rename from src/Core/Models/Api/IdentityDataModel.cs rename to src/Core/Models/Data/CipherIdentityData.cs index 990e233eaa..a17d3bafb6 100644 --- a/src/Core/Models/Api/IdentityDataModel.cs +++ b/src/Core/Models/Data/CipherIdentityData.cs @@ -1,19 +1,14 @@ -using System; -using Bit.Core.Models.Table; -using Newtonsoft.Json; +using Bit.Core.Models.Api; -namespace Bit.Core.Models.Api +namespace Bit.Core.Models.Data { - public class IdentityDataModel : CipherDataModel + public class CipherIdentityData : CipherData { - public IdentityDataModel() { } + public CipherIdentityData() { } - public IdentityDataModel(CipherRequestModel cipher) + public CipherIdentityData(CipherRequestModel cipher) + : base(cipher) { - Name = cipher.Name; - Notes = cipher.Notes; - Fields = cipher.Fields; - Title = cipher.Identity.Title; FirstName = cipher.Identity.FirstName; MiddleName = cipher.Identity.MiddleName; @@ -34,39 +29,6 @@ namespace Bit.Core.Models.Api LicenseNumber = cipher.Identity.LicenseNumber; } - 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; - Username = data.Username; - PassportNumber = data.PassportNumber; - LicenseNumber = data.LicenseNumber; - } - public string Title { get; set; } public string FirstName { get; set; } public string MiddleName { get; set; } diff --git a/src/Core/Models/Data/CipherLoginData.cs b/src/Core/Models/Data/CipherLoginData.cs new file mode 100644 index 0000000000..af9c117c2c --- /dev/null +++ b/src/Core/Models/Data/CipherLoginData.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using Bit.Core.Enums; +using Bit.Core.Models.Api; + +namespace Bit.Core.Models.Data +{ + public class CipherLoginData : CipherData + { + public CipherLoginData() { } + + public CipherLoginData(CipherRequestModel cipher) + : base(cipher) + { + Uris = cipher.Login.Uris?.Where(u => u != null).Select(u => new LoginDataUriModel(u)); + Username = cipher.Login.Username; + Password = cipher.Login.Password; + Totp = cipher.Login.Totp; + } + + public IEnumerable Uris { get; set; } + public string Username { get; set; } + public string Password { get; set; } + public string Totp { get; set; } + + public class LoginDataUriModel + { + public LoginDataUriModel() { } + + public LoginDataUriModel(CipherLoginModel.LoginApiUriModel uri) + { + Uri = uri.Uri; + MatchType = uri.MatchType; + } + + public string Uri { get; set; } + public UriMatchType MatchType { get; set; } + } + } +} diff --git a/src/Core/Models/Data/CipherSecureNoteData.cs b/src/Core/Models/Data/CipherSecureNoteData.cs new file mode 100644 index 0000000000..e7845d2bf7 --- /dev/null +++ b/src/Core/Models/Data/CipherSecureNoteData.cs @@ -0,0 +1,18 @@ +using Bit.Core.Enums; +using Bit.Core.Models.Api; + +namespace Bit.Core.Models.Data +{ + public class CipherSecureNoteData : CipherData + { + public CipherSecureNoteData() { } + + public CipherSecureNoteData(CipherRequestModel cipher) + : base(cipher) + { + Type = cipher.SecureNote.Type; + } + + public SecureNoteType Type { get; set; } + } +}