1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-24 16:38:22 +01:00

field and password history domains/views

This commit is contained in:
Kyle Spearrin 2019-04-12 17:21:21 -04:00
parent 52a978a59a
commit d136eee224
4 changed files with 127 additions and 0 deletions

View File

@ -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<string> _map = new HashSet<string>
{
"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<FieldView> DecryptAsync(string orgId)
{
return DecryptObjAsync(new FieldView(this), this, _map, orgId);
}
public FieldData ToLoginUriData()
{
var f = new FieldData();
BuildDataModel(this, f, new HashSet<string>
{
"Name",
"Value",
"Type"
}, new HashSet<string>
{
"Type"
});
return f;
}
}
}

View File

@ -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<string> _map = new HashSet<string>
{
"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<PasswordHistoryView> 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;
}
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}