mirror of
https://github.com/bitwarden/mobile
synced 2026-01-08 03:23:23 +00:00
sync and display custom fields for login
This commit is contained in:
11
src/App/Models/Api/CipherDataModel.cs
Normal file
11
src/App/Models/Api/CipherDataModel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public abstract class CipherDataModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public IEnumerable<FieldDataModel> Fields { get; set; }
|
||||
}
|
||||
}
|
||||
11
src/App/Models/Api/FieldDataModel.cs
Normal file
11
src/App/Models/Api/FieldDataModel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Bit.App.Enums;
|
||||
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class FieldDataModel
|
||||
{
|
||||
public FieldType Type { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class FolderDataModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
namespace Bit.App.Models.Api
|
||||
{
|
||||
public class LoginDataModel
|
||||
public class LoginDataModel : CipherDataModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string Totp { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using SQLite;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Models.Api;
|
||||
using Newtonsoft.Json;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.App.Models.Data
|
||||
{
|
||||
@@ -11,23 +13,6 @@ namespace Bit.App.Models.Data
|
||||
public LoginData()
|
||||
{ }
|
||||
|
||||
public LoginData(Login login, string userId)
|
||||
{
|
||||
Id = login.Id;
|
||||
FolderId = login.FolderId;
|
||||
UserId = userId;
|
||||
OrganizationId = login.OrganizationId;
|
||||
Name = login.Name?.EncryptedString;
|
||||
Uri = login.Uri?.EncryptedString;
|
||||
Username = login.Username?.EncryptedString;
|
||||
Password = login.Password?.EncryptedString;
|
||||
Notes = login.Notes?.EncryptedString;
|
||||
Totp = login?.Notes?.EncryptedString;
|
||||
Favorite = login.Favorite;
|
||||
Edit = login.Edit;
|
||||
OrganizationUseTotp = login.OrganizationUseTotp;
|
||||
}
|
||||
|
||||
public LoginData(CipherResponse cipher, string userId)
|
||||
{
|
||||
if(cipher.Type != Enums.CipherType.Login)
|
||||
@@ -51,6 +36,15 @@ namespace Bit.App.Models.Data
|
||||
Edit = cipher.Edit;
|
||||
OrganizationUseTotp = cipher.OrganizationUseTotp;
|
||||
RevisionDateTime = cipher.RevisionDate;
|
||||
|
||||
if(data.Fields != null && data.Fields.Any())
|
||||
{
|
||||
try
|
||||
{
|
||||
Fields = JsonConvert.SerializeObject(data.Fields);
|
||||
}
|
||||
catch(JsonSerializationException) { }
|
||||
}
|
||||
}
|
||||
|
||||
[PrimaryKey]
|
||||
@@ -65,6 +59,7 @@ namespace Bit.App.Models.Data
|
||||
public string Password { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string Totp { get; set; }
|
||||
public string Fields { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
public bool Edit { get; set; }
|
||||
public bool OrganizationUseTotp { get; set; }
|
||||
|
||||
19
src/App/Models/Field.cs
Normal file
19
src/App/Models/Field.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Bit.App.Enums;
|
||||
using Bit.App.Models.Api;
|
||||
|
||||
namespace Bit.App.Models
|
||||
{
|
||||
public class Field
|
||||
{
|
||||
public Field(FieldDataModel model)
|
||||
{
|
||||
Type = model.Type;
|
||||
Name = new CipherString(model.Name);
|
||||
Value = new CipherString(model.Value);
|
||||
}
|
||||
|
||||
public FieldType Type { get; set; }
|
||||
public CipherString Name { get; set; }
|
||||
public CipherString Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Bit.App.Models.Api;
|
||||
using Bit.App.Models.Data;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -26,6 +27,16 @@ namespace Bit.App.Models
|
||||
Edit = data.Edit;
|
||||
OrganizationUseTotp = data.OrganizationUseTotp;
|
||||
Attachments = attachments?.Select(a => new Attachment(a));
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(data.Fields))
|
||||
{
|
||||
try
|
||||
{
|
||||
var fieldModels = JsonConvert.DeserializeObject<IEnumerable<FieldDataModel>>(data.Fields);
|
||||
Fields = fieldModels?.Select(f => new Field(f));
|
||||
}
|
||||
catch(JsonSerializationException) { }
|
||||
}
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
@@ -38,14 +49,10 @@ namespace Bit.App.Models
|
||||
public CipherString Password { get; set; }
|
||||
public CipherString Notes { get; set; }
|
||||
public CipherString Totp { get; set; }
|
||||
public IEnumerable<Field> Fields { get; set; }
|
||||
public bool Favorite { get; set; }
|
||||
public bool Edit { get; set; }
|
||||
public bool OrganizationUseTotp { get; set; }
|
||||
public IEnumerable<Attachment> Attachments { get; set; }
|
||||
|
||||
public LoginData ToLoginData(string userId)
|
||||
{
|
||||
return new LoginData(this, userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.ComponentModel;
|
||||
using Bit.App.Resources;
|
||||
using Xamarin.Forms;
|
||||
using System.Collections.Generic;
|
||||
using Bit.App.Enums;
|
||||
|
||||
namespace Bit.App.Models.Page
|
||||
{
|
||||
@@ -17,6 +18,7 @@ namespace Bit.App.Models.Page
|
||||
private int _totpSec = 30;
|
||||
private bool _revealPassword;
|
||||
private List<Attachment> _attachments;
|
||||
private List<Field> _fields;
|
||||
|
||||
public VaultViewLoginPageModel() { }
|
||||
|
||||
@@ -144,12 +146,10 @@ namespace Bit.App.Models.Page
|
||||
_revealPassword = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(RevealPassword)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(MaskedPassword)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowHideText)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowHideImage)));
|
||||
}
|
||||
}
|
||||
public string MaskedPassword => RevealPassword ? Password : Password == null ? null : new string('●', Password.Length);
|
||||
public string ShowHideText => RevealPassword ? AppResources.Hide : AppResources.Show;
|
||||
public ImageSource ShowHideImage => RevealPassword ? ImageSource.FromFile("eye_slash") : ImageSource.FromFile("eye");
|
||||
|
||||
public string TotpCode
|
||||
@@ -189,6 +189,18 @@ namespace Bit.App.Models.Page
|
||||
}
|
||||
public bool ShowAttachments => (Attachments?.Count ?? 0) > 0;
|
||||
|
||||
public List<Field> Fields
|
||||
{
|
||||
get { return _fields; }
|
||||
set
|
||||
{
|
||||
_fields = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Fields)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowFields)));
|
||||
}
|
||||
}
|
||||
public bool ShowFields => (Fields?.Count ?? 0) > 0;
|
||||
|
||||
public void Update(Login login)
|
||||
{
|
||||
Name = login.Name?.Decrypt(login.OrganizationId);
|
||||
@@ -217,6 +229,25 @@ namespace Bit.App.Models.Page
|
||||
{
|
||||
login.Attachments = null;
|
||||
}
|
||||
|
||||
if(login.Fields != null)
|
||||
{
|
||||
var fields = new List<Field>();
|
||||
foreach(var field in login.Fields)
|
||||
{
|
||||
fields.Add(new Field
|
||||
{
|
||||
Name = field.Name?.Decrypt(login.OrganizationId),
|
||||
Value = field.Value?.Decrypt(login.OrganizationId),
|
||||
Type = field.Type
|
||||
});
|
||||
}
|
||||
Fields = fields;
|
||||
}
|
||||
else
|
||||
{
|
||||
login.Fields = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Attachment
|
||||
@@ -227,5 +258,26 @@ namespace Bit.App.Models.Page
|
||||
public long Size { get; set; }
|
||||
public string Url { get; set; }
|
||||
}
|
||||
|
||||
public class Field
|
||||
{
|
||||
private string _maskedValue;
|
||||
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string MaskedValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_maskedValue == null && Value != null)
|
||||
{
|
||||
_maskedValue = new string('●', Value.Length);
|
||||
}
|
||||
|
||||
return _maskedValue;
|
||||
}
|
||||
}
|
||||
public FieldType Type { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user