diff --git a/src/Core/Models/Domain/Field.cs b/src/Core/Models/Domain/Field.cs new file mode 100644 index 000000000..677055bc2 --- /dev/null +++ b/src/Core/Models/Domain/Field.cs @@ -0,0 +1,49 @@ +using Bit.Core.Enums; +using Bit.Core.Models.Data; +using Bit.Core.Models.View; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bit.Core.Models.Domain +{ + public class Field : Domain + { + private HashSet _map = new HashSet + { + "Name", + "Value" + }; + + public Field() { } + + public Field(FieldData obj, bool alreadyEncrypted = false) + { + Type = obj.Type; + BuildDomainModel(this, obj, _map, alreadyEncrypted); + } + + public CipherString Name { get; set; } + public CipherString Value { get; set; } + public FieldType Type { get; set; } + + public Task DecryptAsync(string orgId) + { + return DecryptObjAsync(new FieldView(this), this, _map, orgId); + } + + public FieldData ToLoginUriData() + { + var f = new FieldData(); + BuildDataModel(this, f, new HashSet + { + "Name", + "Value", + "Type" + }, new HashSet + { + "Type" + }); + return f; + } + } +} diff --git a/src/Core/Models/Domain/PasswordHistory.cs b/src/Core/Models/Domain/PasswordHistory.cs new file mode 100644 index 000000000..1f9ed732e --- /dev/null +++ b/src/Core/Models/Domain/PasswordHistory.cs @@ -0,0 +1,40 @@ +using Bit.Core.Models.Data; +using Bit.Core.Models.View; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Bit.Core.Models.Domain +{ + public class PasswordHistory : Domain + { + private HashSet _map = new HashSet + { + "Password" + }; + + public PasswordHistory() { } + + public PasswordHistory(PasswordHistoryData obj, bool alreadyEncrypted = false) + { + BuildDomainModel(this, obj, _map, alreadyEncrypted); + LastUsedDate = obj.LastUsedDate.GetValueOrDefault(); + } + + public CipherString Password { get; set; } + public DateTime LastUsedDate { get; set; } + + public Task DecryptAsync(string orgId) + { + return DecryptObjAsync(new PasswordHistoryView(this), this, _map, orgId); + } + + public PasswordHistoryData ToLoginUriData() + { + var ph = new PasswordHistoryData(); + ph.LastUsedDate = LastUsedDate; + BuildDataModel(this, ph, _map); + return ph; + } + } +} diff --git a/src/Core/Models/View/FieldView.cs b/src/Core/Models/View/FieldView.cs new file mode 100644 index 000000000..5fa93a68f --- /dev/null +++ b/src/Core/Models/View/FieldView.cs @@ -0,0 +1,20 @@ +using Bit.Core.Enums; +using Bit.Core.Models.Domain; + +namespace Bit.Core.Models.View +{ + public class FieldView : View + { + public FieldView() { } + + public FieldView(Field f) + { + Type = f.Type; + } + + public string Name { get; set; } + public string Value { get; set; } + public FieldType Type { get; set; } + public string MaskedValue => Value != null ? "••••••••" : null; + } +} diff --git a/src/Core/Models/View/PasswordHistoryView.cs b/src/Core/Models/View/PasswordHistoryView.cs new file mode 100644 index 000000000..cb3b52d6a --- /dev/null +++ b/src/Core/Models/View/PasswordHistoryView.cs @@ -0,0 +1,18 @@ +using Bit.Core.Models.Domain; +using System; + +namespace Bit.Core.Models.View +{ + public class PasswordHistoryView : View + { + public PasswordHistoryView() { } + + public PasswordHistoryView(PasswordHistory ph) + { + LastUsedDate = ph.LastUsedDate; + } + + public string Password { get; set; } + public DateTime? LastUsedDate { get; set; } + } +}