mirror of
https://github.com/bitwarden/mobile
synced 2025-12-05 23:53:33 +00:00
more renames
This commit is contained in:
284
src/App/Models/Page/VaultViewCipherPageModel.cs
Normal file
284
src/App/Models/Page/VaultViewCipherPageModel.cs
Normal file
@@ -0,0 +1,284 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Bit.App.Resources;
|
||||
using Xamarin.Forms;
|
||||
using System.Collections.Generic;
|
||||
using Bit.App.Enums;
|
||||
|
||||
namespace Bit.App.Models.Page
|
||||
{
|
||||
public class VaultViewCipherPageModel : INotifyPropertyChanged
|
||||
{
|
||||
private string _name;
|
||||
private string _username;
|
||||
private string _password;
|
||||
private string _uri;
|
||||
private string _notes;
|
||||
private string _totpCode;
|
||||
private int _totpSec = 30;
|
||||
private bool _revealPassword;
|
||||
private List<Attachment> _attachments;
|
||||
private List<Field> _fields;
|
||||
|
||||
public VaultViewCipherPageModel() { }
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set
|
||||
{
|
||||
_name = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Name)));
|
||||
}
|
||||
}
|
||||
public string Username
|
||||
{
|
||||
get { return _username; }
|
||||
set
|
||||
{
|
||||
_username = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Username)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowUsername)));
|
||||
}
|
||||
}
|
||||
public bool ShowUsername => !string.IsNullOrWhiteSpace(Username);
|
||||
|
||||
public string Password
|
||||
{
|
||||
get { return _password; }
|
||||
set
|
||||
{
|
||||
_password = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Password)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(MaskedPassword)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowPassword)));
|
||||
}
|
||||
}
|
||||
public bool ShowPassword => !string.IsNullOrWhiteSpace(Password);
|
||||
|
||||
public string Uri
|
||||
{
|
||||
get { return _uri; }
|
||||
set
|
||||
{
|
||||
_uri = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Uri)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(UriHost)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowUri)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowLaunch)));
|
||||
}
|
||||
}
|
||||
public bool ShowUri => !string.IsNullOrWhiteSpace(Uri);
|
||||
|
||||
public bool ShowLaunch
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!ShowUri)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Device.RuntimePlatform == Device.Android && !Uri.StartsWith("http") &&
|
||||
!Uri.StartsWith("androidapp://"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Device.RuntimePlatform != Device.Android && !Uri.StartsWith("http"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Uri uri;
|
||||
if(!System.Uri.TryCreate(Uri, UriKind.Absolute, out uri))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public string UriHost
|
||||
{
|
||||
get
|
||||
{
|
||||
if(!ShowUri)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Uri uri;
|
||||
if(!System.Uri.TryCreate(Uri, UriKind.Absolute, out uri))
|
||||
{
|
||||
return Uri;
|
||||
}
|
||||
|
||||
string domain;
|
||||
if(DomainName.TryParseBaseDomain(uri.Host, out domain))
|
||||
{
|
||||
return domain;
|
||||
}
|
||||
|
||||
return uri.Host;
|
||||
}
|
||||
}
|
||||
|
||||
public string Notes
|
||||
{
|
||||
get { return _notes; }
|
||||
set
|
||||
{
|
||||
_notes = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Notes)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowNotes)));
|
||||
}
|
||||
}
|
||||
public bool ShowNotes => !string.IsNullOrWhiteSpace(Notes);
|
||||
public bool RevealPassword
|
||||
{
|
||||
get { return _revealPassword; }
|
||||
set
|
||||
{
|
||||
_revealPassword = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(RevealPassword)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(MaskedPassword)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowHideImage)));
|
||||
}
|
||||
}
|
||||
public string MaskedPassword => RevealPassword ? Password : Password == null ? null : new string('●', Password.Length);
|
||||
public ImageSource ShowHideImage => RevealPassword ? ImageSource.FromFile("eye_slash") : ImageSource.FromFile("eye");
|
||||
|
||||
public string TotpCode
|
||||
{
|
||||
get { return _totpCode; }
|
||||
set
|
||||
{
|
||||
_totpCode = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(TotpCode)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(TotpCodeFormatted)));
|
||||
}
|
||||
}
|
||||
public int TotpSecond
|
||||
{
|
||||
get { return _totpSec; }
|
||||
set
|
||||
{
|
||||
_totpSec = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(TotpSecond)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(TotpColor)));
|
||||
}
|
||||
}
|
||||
public bool TotpLow => TotpSecond <= 7;
|
||||
public Color TotpColor => !string.IsNullOrWhiteSpace(TotpCode) && TotpLow ? Color.Red : Color.Black;
|
||||
public string TotpCodeFormatted => !string.IsNullOrWhiteSpace(TotpCode) ?
|
||||
string.Format("{0} {1}", TotpCode.Substring(0, 3), TotpCode.Substring(3)) : null;
|
||||
|
||||
public List<Attachment> Attachments
|
||||
{
|
||||
get { return _attachments; }
|
||||
set
|
||||
{
|
||||
_attachments = value;
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Attachments)));
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(nameof(ShowAttachments)));
|
||||
}
|
||||
}
|
||||
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(Cipher cipher)
|
||||
{
|
||||
Name = cipher.Name?.Decrypt(cipher.OrganizationId);
|
||||
Username = cipher.Login?.Username?.Decrypt(cipher.OrganizationId);
|
||||
Password = cipher.Login?.Password?.Decrypt(cipher.OrganizationId);
|
||||
Uri = cipher.Login?.Uri?.Decrypt(cipher.OrganizationId);
|
||||
Notes = cipher.Notes?.Decrypt(cipher.OrganizationId);
|
||||
|
||||
if(cipher.Attachments != null)
|
||||
{
|
||||
var attachments = new List<Attachment>();
|
||||
foreach(var attachment in cipher.Attachments)
|
||||
{
|
||||
attachments.Add(new Attachment
|
||||
{
|
||||
Id = attachment.Id,
|
||||
Name = attachment.FileName?.Decrypt(cipher.OrganizationId),
|
||||
SizeName = attachment.SizeName,
|
||||
Size = attachment.Size,
|
||||
Url = attachment.Url
|
||||
});
|
||||
}
|
||||
Attachments = attachments;
|
||||
}
|
||||
else
|
||||
{
|
||||
cipher.Attachments = null;
|
||||
}
|
||||
|
||||
if(cipher.Fields != null)
|
||||
{
|
||||
var fields = new List<Field>();
|
||||
foreach(var field in cipher.Fields)
|
||||
{
|
||||
fields.Add(new Field
|
||||
{
|
||||
Name = field.Name?.Decrypt(cipher.OrganizationId),
|
||||
Value = field.Value?.Decrypt(cipher.OrganizationId),
|
||||
Type = field.Type
|
||||
});
|
||||
}
|
||||
Fields = fields;
|
||||
}
|
||||
else
|
||||
{
|
||||
cipher.Fields = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Attachment
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string SizeName { get; set; }
|
||||
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; }
|
||||
public bool Revealed { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user