2016-05-02 09:52:09 +03:00
|
|
|
|
using System;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
using Acr.UserDialogs;
|
|
|
|
|
using Bit.App.Abstractions;
|
2016-05-13 07:11:32 +03:00
|
|
|
|
using Bit.App.Controls;
|
2016-05-08 06:11:47 +03:00
|
|
|
|
using Bit.App.Models.Page;
|
2016-05-07 20:42:09 +03:00
|
|
|
|
using Bit.App.Resources;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
using Xamarin.Forms;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
using XLabs.Ioc;
|
2017-02-17 08:16:09 +03:00
|
|
|
|
using System.Threading.Tasks;
|
2017-05-30 21:13:53 +03:00
|
|
|
|
using Bit.App.Utilities;
|
2017-07-13 17:51:45 +03:00
|
|
|
|
using System.Collections.Generic;
|
2017-07-13 19:08:48 +03:00
|
|
|
|
using Bit.App.Models;
|
2017-07-22 22:38:08 +03:00
|
|
|
|
using System.Linq;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2016-05-03 00:50:16 +03:00
|
|
|
|
namespace Bit.App.Pages
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
public class VaultViewLoginPage : ExtendedContentPage
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
private readonly string _loginId;
|
|
|
|
|
private readonly ILoginService _loginService;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
private readonly IUserDialogs _userDialogs;
|
2017-07-13 06:09:44 +03:00
|
|
|
|
private readonly IDeviceActionService _deviceActionService;
|
2017-07-13 21:44:02 +03:00
|
|
|
|
private readonly ITokenService _tokenService;
|
2017-07-24 19:26:34 +03:00
|
|
|
|
private bool _pageDisappeared = true;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
public VaultViewLoginPage(string loginId)
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
_loginId = loginId;
|
|
|
|
|
_loginService = Resolver.Resolve<ILoginService>();
|
2016-05-07 05:29:03 +03:00
|
|
|
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
2017-07-13 06:09:44 +03:00
|
|
|
|
_deviceActionService = Resolver.Resolve<IDeviceActionService>();
|
2017-07-13 21:44:02 +03:00
|
|
|
|
_tokenService = Resolver.Resolve<ITokenService>();
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
private VaultViewLoginPageModel Model { get; set; } = new VaultViewLoginPageModel();
|
2016-05-14 02:57:07 +03:00
|
|
|
|
private ExtendedTableView Table { get; set; }
|
2017-01-03 08:17:15 +03:00
|
|
|
|
private TableSection LoginInformationSection { get; set; }
|
2016-06-14 03:03:16 +03:00
|
|
|
|
private TableSection NotesSection { get; set; }
|
2017-07-12 23:23:24 +03:00
|
|
|
|
private TableSection AttachmentsSection { get; set; }
|
2016-06-14 03:03:16 +03:00
|
|
|
|
public LabeledValueCell UsernameCell { get; set; }
|
|
|
|
|
public LabeledValueCell PasswordCell { get; set; }
|
|
|
|
|
public LabeledValueCell UriCell { get; set; }
|
2017-04-20 23:07:34 +03:00
|
|
|
|
public LabeledValueCell NotesCell { get; set; }
|
2017-07-13 21:44:02 +03:00
|
|
|
|
public LabeledValueCell TotpCodeCell { get; set; }
|
2017-02-17 08:16:09 +03:00
|
|
|
|
private EditLoginToolBarItem EditItem { get; set; }
|
2017-07-13 17:51:45 +03:00
|
|
|
|
public List<AttachmentViewCell> AttachmentCells { get; set; }
|
2016-05-08 06:11:47 +03:00
|
|
|
|
|
|
|
|
|
private void Init()
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2017-02-17 08:16:09 +03:00
|
|
|
|
EditItem = new EditLoginToolBarItem(this, _loginId);
|
|
|
|
|
ToolbarItems.Add(EditItem);
|
2017-05-30 21:13:53 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.iOS)
|
2016-05-14 08:34:42 +03:00
|
|
|
|
{
|
|
|
|
|
ToolbarItems.Add(new DismissModalToolBarItem(this));
|
|
|
|
|
}
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-06-18 01:14:24 +03:00
|
|
|
|
// Name
|
2016-05-14 02:57:07 +03:00
|
|
|
|
var nameCell = new LabeledValueCell(AppResources.Name);
|
2017-05-30 21:13:53 +03:00
|
|
|
|
nameCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewLoginPageModel.Name));
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
|
|
|
|
// Username
|
2016-06-14 03:03:16 +03:00
|
|
|
|
UsernameCell = new LabeledValueCell(AppResources.Username, button1Text: AppResources.Copy);
|
2017-05-30 21:13:53 +03:00
|
|
|
|
UsernameCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewLoginPageModel.Username));
|
|
|
|
|
UsernameCell.Value.SetBinding(Label.FontSizeProperty, nameof(VaultViewLoginPageModel.UsernameFontSize));
|
2016-06-14 03:03:16 +03:00
|
|
|
|
UsernameCell.Button1.Command = new Command(() => Copy(Model.Username, AppResources.Username));
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// Password
|
2016-08-17 05:18:45 +03:00
|
|
|
|
PasswordCell = new LabeledValueCell(AppResources.Password, button1Text: string.Empty,
|
|
|
|
|
button2Text: AppResources.Copy);
|
2017-05-30 21:13:53 +03:00
|
|
|
|
PasswordCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewLoginPageModel.MaskedPassword));
|
|
|
|
|
PasswordCell.Value.SetBinding(Label.FontSizeProperty, nameof(VaultViewLoginPageModel.PasswordFontSize));
|
2017-05-30 21:24:29 +03:00
|
|
|
|
PasswordCell.Button1.SetBinding(Button.ImageProperty, nameof(VaultViewLoginPageModel.ShowHideImage));
|
2017-05-30 21:13:53 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.iOS)
|
2016-06-18 01:14:24 +03:00
|
|
|
|
{
|
|
|
|
|
PasswordCell.Button1.Margin = new Thickness(10, 0);
|
|
|
|
|
}
|
2016-06-14 03:03:16 +03:00
|
|
|
|
PasswordCell.Button1.Command = new Command(() => Model.RevealPassword = !Model.RevealPassword);
|
|
|
|
|
PasswordCell.Button2.Command = new Command(() => Copy(Model.Password, AppResources.Password));
|
2017-05-30 21:13:53 +03:00
|
|
|
|
PasswordCell.Value.FontFamily = Helpers.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2016-05-08 06:11:47 +03:00
|
|
|
|
// URI
|
2016-06-14 03:03:16 +03:00
|
|
|
|
UriCell = new LabeledValueCell(AppResources.Website, button1Text: AppResources.Launch);
|
2017-05-30 21:13:53 +03:00
|
|
|
|
UriCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewLoginPageModel.UriHost));
|
2017-06-03 00:09:09 +03:00
|
|
|
|
UriCell.Button1.SetBinding(IsVisibleProperty, nameof(VaultViewLoginPageModel.ShowLaunch));
|
2017-06-08 23:22:11 +03:00
|
|
|
|
UriCell.Button1.Command = new Command(() =>
|
|
|
|
|
{
|
|
|
|
|
if(Device.RuntimePlatform == Device.Android && Model.Uri.StartsWith("androidapp://"))
|
|
|
|
|
{
|
|
|
|
|
MessagingCenter.Send(Application.Current, "LaunchApp", Model.Uri);
|
|
|
|
|
}
|
|
|
|
|
else if(Model.Uri.StartsWith("http://") || Model.Uri.StartsWith("https://"))
|
|
|
|
|
{
|
|
|
|
|
Device.OpenUri(new Uri(Model.Uri));
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
2017-07-13 21:44:02 +03:00
|
|
|
|
// Totp
|
|
|
|
|
TotpCodeCell = new LabeledValueCell(AppResources.VerificationCodeTotp, button1Text: AppResources.Copy, subText: "--");
|
|
|
|
|
TotpCodeCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewLoginPageModel.TotpCodeFormatted));
|
|
|
|
|
TotpCodeCell.Value.SetBinding(Label.TextColorProperty, nameof(VaultViewLoginPageModel.TotpColor));
|
|
|
|
|
TotpCodeCell.Button1.Command = new Command(() => Copy(Model.TotpCode, AppResources.VerificationCodeTotp));
|
|
|
|
|
TotpCodeCell.Sub.SetBinding(Label.TextProperty, nameof(VaultViewLoginPageModel.TotpSecond));
|
|
|
|
|
TotpCodeCell.Sub.SetBinding(Label.TextColorProperty, nameof(VaultViewLoginPageModel.TotpColor));
|
|
|
|
|
TotpCodeCell.Value.FontFamily = Helpers.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
|
|
|
|
|
|
2016-05-14 02:57:07 +03:00
|
|
|
|
// Notes
|
2017-04-20 23:07:34 +03:00
|
|
|
|
NotesCell = new LabeledValueCell();
|
2017-05-30 21:13:53 +03:00
|
|
|
|
NotesCell.Value.SetBinding(Label.TextProperty, nameof(VaultViewLoginPageModel.Notes));
|
2017-04-20 23:07:34 +03:00
|
|
|
|
NotesCell.Value.LineBreakMode = LineBreakMode.WordWrap;
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection = new TableSection(AppResources.LoginInformation)
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
|
|
|
|
nameCell
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NotesSection = new TableSection(AppResources.Notes)
|
|
|
|
|
{
|
2017-04-20 23:07:34 +03:00
|
|
|
|
NotesCell
|
2016-06-14 03:03:16 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-05-14 02:57:07 +03:00
|
|
|
|
Table = new ExtendedTableView
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2016-05-14 02:57:07 +03:00
|
|
|
|
Intent = TableIntent.Settings,
|
2016-05-24 06:48:34 +03:00
|
|
|
|
EnableScrolling = true,
|
2016-05-14 02:57:07 +03:00
|
|
|
|
HasUnevenRows = true,
|
2017-07-13 17:51:45 +03:00
|
|
|
|
EnableSelection = true,
|
2016-05-14 02:57:07 +03:00
|
|
|
|
Root = new TableRoot
|
|
|
|
|
{
|
2017-07-13 18:16:00 +03:00
|
|
|
|
LoginInformationSection
|
2016-05-14 02:57:07 +03:00
|
|
|
|
}
|
2016-05-08 06:11:47 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-30 21:13:53 +03:00
|
|
|
|
if(Device.RuntimePlatform == Device.iOS)
|
2016-05-14 02:57:07 +03:00
|
|
|
|
{
|
|
|
|
|
Table.RowHeight = -1;
|
|
|
|
|
Table.EstimatedRowHeight = 70;
|
|
|
|
|
}
|
2017-05-30 21:13:53 +03:00
|
|
|
|
else if(Device.RuntimePlatform == Device.Android)
|
2016-11-08 07:45:46 +03:00
|
|
|
|
{
|
2016-11-26 01:15:34 +03:00
|
|
|
|
// NOTE: This is going to cause problems with i18n strings since various languages have difference string sizes
|
2016-11-08 07:45:46 +03:00
|
|
|
|
PasswordCell.Button1.WidthRequest = 40;
|
2016-12-07 06:36:33 +03:00
|
|
|
|
PasswordCell.Button2.WidthRequest = 59;
|
|
|
|
|
UsernameCell.Button1.WidthRequest = 59;
|
2017-07-13 21:44:02 +03:00
|
|
|
|
TotpCodeCell.Button1.WidthRequest = 59;
|
2016-12-07 06:31:07 +03:00
|
|
|
|
UriCell.Button1.WidthRequest = 75;
|
2016-11-08 07:45:46 +03:00
|
|
|
|
}
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
Title = AppResources.ViewLogin;
|
2016-05-24 06:48:34 +03:00
|
|
|
|
Content = Table;
|
2016-05-08 06:11:47 +03:00
|
|
|
|
BindingContext = Model;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-07 07:00:12 +03:00
|
|
|
|
protected async override void OnAppearing()
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2017-07-24 19:26:34 +03:00
|
|
|
|
_pageDisappeared = false;
|
2017-04-20 23:07:34 +03:00
|
|
|
|
NotesCell.Tapped += NotesCell_Tapped;
|
2017-02-17 08:16:09 +03:00
|
|
|
|
EditItem.InitEvents();
|
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
var login = await _loginService.GetByIdAsync(_loginId);
|
|
|
|
|
if(login == null)
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2016-08-30 06:50:22 +03:00
|
|
|
|
await Navigation.PopForDeviceAsync();
|
2016-05-08 06:11:47 +03:00
|
|
|
|
return;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
2016-05-08 06:11:47 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
Model.Update(login);
|
2016-05-12 00:30:09 +03:00
|
|
|
|
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(LoginInformationSection.Contains(UriCell))
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Remove(UriCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(Model.ShowUri)
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Add(UriCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(LoginInformationSection.Contains(UsernameCell))
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Remove(UsernameCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(Model.ShowUsername)
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Add(UsernameCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(LoginInformationSection.Contains(PasswordCell))
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Remove(PasswordCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(Model.ShowPassword)
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
LoginInformationSection.Add(PasswordCell);
|
2016-06-14 03:03:16 +03:00
|
|
|
|
}
|
2016-05-14 02:57:07 +03:00
|
|
|
|
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(Table.Root.Contains(NotesSection))
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
|
|
|
|
Table.Root.Remove(NotesSection);
|
|
|
|
|
}
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(Model.ShowNotes)
|
2016-06-14 03:03:16 +03:00
|
|
|
|
{
|
|
|
|
|
Table.Root.Add(NotesSection);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-22 22:38:08 +03:00
|
|
|
|
// Totp
|
|
|
|
|
if(LoginInformationSection.Contains(TotpCodeCell))
|
2017-07-12 23:23:24 +03:00
|
|
|
|
{
|
2017-07-22 22:38:08 +03:00
|
|
|
|
LoginInformationSection.Remove(TotpCodeCell);
|
2017-07-12 23:23:24 +03:00
|
|
|
|
}
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(login.Totp != null && (_tokenService.TokenPremium || login.OrganizationUseTotp))
|
2017-07-13 21:44:02 +03:00
|
|
|
|
{
|
|
|
|
|
var totpKey = login.Totp.Decrypt(login.OrganizationId);
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(!string.IsNullOrWhiteSpace(totpKey))
|
2017-07-13 21:44:02 +03:00
|
|
|
|
{
|
|
|
|
|
Model.TotpCode = Crypto.Totp(totpKey);
|
2017-07-22 22:38:08 +03:00
|
|
|
|
if(!string.IsNullOrWhiteSpace(Model.TotpCode))
|
2017-07-13 21:44:02 +03:00
|
|
|
|
{
|
|
|
|
|
TotpTick(totpKey);
|
|
|
|
|
Device.StartTimer(new TimeSpan(0, 0, 1), () =>
|
|
|
|
|
{
|
2017-07-24 19:26:34 +03:00
|
|
|
|
if(_pageDisappeared)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 21:44:02 +03:00
|
|
|
|
TotpTick(totpKey);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
2017-07-22 22:38:08 +03:00
|
|
|
|
LoginInformationSection.Add(TotpCodeCell);
|
2017-07-13 21:44:02 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-22 22:38:08 +03:00
|
|
|
|
CleanupAttachmentCells();
|
|
|
|
|
if(Table.Root.Contains(AttachmentsSection))
|
2017-07-13 21:44:02 +03:00
|
|
|
|
{
|
2017-07-22 22:38:08 +03:00
|
|
|
|
Table.Root.Remove(AttachmentsSection);
|
|
|
|
|
}
|
2017-07-24 17:34:22 +03:00
|
|
|
|
if(Model.ShowAttachments && _tokenService.TokenPremium)
|
2017-07-22 22:38:08 +03:00
|
|
|
|
{
|
|
|
|
|
AttachmentsSection = new TableSection(AppResources.Attachments);
|
|
|
|
|
AttachmentCells = new List<AttachmentViewCell>();
|
|
|
|
|
foreach(var attachment in Model.Attachments.OrderBy(s => s.Name))
|
|
|
|
|
{
|
|
|
|
|
var attachmentCell = new AttachmentViewCell(attachment, async () =>
|
|
|
|
|
{
|
|
|
|
|
await OpenAttachmentAsync(login, attachment);
|
|
|
|
|
});
|
|
|
|
|
AttachmentCells.Add(attachmentCell);
|
|
|
|
|
AttachmentsSection.Add(attachmentCell);
|
|
|
|
|
attachmentCell.InitEvents();
|
|
|
|
|
}
|
|
|
|
|
Table.Root.Add(AttachmentsSection);
|
2017-07-13 21:44:02 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 03:03:16 +03:00
|
|
|
|
base.OnAppearing();
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 08:16:09 +03:00
|
|
|
|
protected override void OnDisappearing()
|
|
|
|
|
{
|
2017-07-24 19:26:34 +03:00
|
|
|
|
_pageDisappeared = true;
|
2017-04-20 23:07:34 +03:00
|
|
|
|
NotesCell.Tapped -= NotesCell_Tapped;
|
2017-02-17 08:16:09 +03:00
|
|
|
|
EditItem.Dispose();
|
2017-07-13 17:51:45 +03:00
|
|
|
|
CleanupAttachmentCells();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CleanupAttachmentCells()
|
|
|
|
|
{
|
|
|
|
|
if(AttachmentCells != null)
|
|
|
|
|
{
|
|
|
|
|
foreach(var cell in AttachmentCells)
|
|
|
|
|
{
|
|
|
|
|
cell.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-17 08:16:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 19:08:48 +03:00
|
|
|
|
private async Task OpenAttachmentAsync(Login login, VaultViewLoginPageModel.Attachment attachment)
|
2017-07-13 06:09:44 +03:00
|
|
|
|
{
|
2017-07-22 00:21:04 +03:00
|
|
|
|
if(!_tokenService.TokenPremium && !login.OrganizationUseTotp)
|
|
|
|
|
{
|
|
|
|
|
_userDialogs.Alert(AppResources.PremiumRequired);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 10 MB warning
|
|
|
|
|
if(attachment.Size >= 10485760 && !(await _userDialogs.ConfirmAsync(
|
2017-07-13 16:01:00 +03:00
|
|
|
|
string.Format(AppResources.AttachmentLargeWarning, attachment.SizeName), null,
|
|
|
|
|
AppResources.Yes, AppResources.No)))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!_deviceActionService.CanOpenFile(attachment.Name))
|
|
|
|
|
{
|
|
|
|
|
await _userDialogs.AlertAsync(AppResources.UnableToOpenFile, null, AppResources.Ok);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 06:45:05 +03:00
|
|
|
|
_userDialogs.ShowLoading(AppResources.Downloading, MaskType.Black);
|
2017-07-13 19:08:48 +03:00
|
|
|
|
var data = await _loginService.DownloadAndDecryptAttachmentAsync(attachment.Url, login.OrganizationId);
|
2017-07-13 06:45:05 +03:00
|
|
|
|
_userDialogs.HideLoading();
|
2017-07-13 06:09:44 +03:00
|
|
|
|
if(data == null)
|
|
|
|
|
{
|
|
|
|
|
await _userDialogs.AlertAsync(AppResources.UnableToDownloadFile, null, AppResources.Ok);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 16:01:00 +03:00
|
|
|
|
if(!_deviceActionService.OpenFile(data, attachment.Id, attachment.Name))
|
2017-07-13 06:09:44 +03:00
|
|
|
|
{
|
|
|
|
|
await _userDialogs.AlertAsync(AppResources.UnableToOpenFile, null, AppResources.Ok);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 23:07:34 +03:00
|
|
|
|
private void NotesCell_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Copy(Model.Notes, AppResources.Notes);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-07 20:42:09 +03:00
|
|
|
|
private void Copy(string copyText, string alertLabel)
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2017-07-22 00:21:04 +03:00
|
|
|
|
_deviceActionService.CopyToClipboard(copyText);
|
|
|
|
|
_userDialogs.Toast(string.Format(AppResources.ValueHasBeenCopied, alertLabel));
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 21:44:02 +03:00
|
|
|
|
private void TotpTick(string totpKey)
|
|
|
|
|
{
|
|
|
|
|
var now = Helpers.EpocUtcNow() / 1000;
|
|
|
|
|
var mod = now % 30;
|
|
|
|
|
Model.TotpSecond = (int)(30 - mod);
|
|
|
|
|
|
|
|
|
|
if(mod == 0)
|
|
|
|
|
{
|
|
|
|
|
Model.TotpCode = Crypto.Totp(totpKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 08:16:09 +03:00
|
|
|
|
private class EditLoginToolBarItem : ExtendedToolbarItem
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
private readonly VaultViewLoginPage _page;
|
|
|
|
|
private readonly string _loginId;
|
2016-05-07 05:29:03 +03:00
|
|
|
|
|
2017-01-03 08:17:15 +03:00
|
|
|
|
public EditLoginToolBarItem(VaultViewLoginPage page, string loginId)
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
|
|
|
|
_page = page;
|
2017-01-03 08:17:15 +03:00
|
|
|
|
_loginId = loginId;
|
2016-05-07 20:42:09 +03:00
|
|
|
|
Text = AppResources.Edit;
|
2017-02-17 08:16:09 +03:00
|
|
|
|
ClickAction = async () => await ClickedItem();
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2017-02-17 08:16:09 +03:00
|
|
|
|
private async Task ClickedItem()
|
2016-05-07 05:29:03 +03:00
|
|
|
|
{
|
2017-01-03 08:17:15 +03:00
|
|
|
|
var page = new VaultEditLoginPage(_loginId);
|
2016-08-30 06:50:22 +03:00
|
|
|
|
await _page.Navigation.PushForDeviceAsync(page);
|
2016-05-07 05:29:03 +03:00
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
2017-07-12 23:23:24 +03:00
|
|
|
|
|
2017-07-13 17:51:45 +03:00
|
|
|
|
public class AttachmentViewCell : LabeledRightDetailCell, IDisposable
|
2017-07-12 23:23:24 +03:00
|
|
|
|
{
|
2017-07-13 07:02:37 +03:00
|
|
|
|
private readonly Action _tapped;
|
2017-07-12 23:23:24 +03:00
|
|
|
|
|
2017-07-13 07:02:37 +03:00
|
|
|
|
public AttachmentViewCell(VaultViewLoginPageModel.Attachment attachment, Action tappedAction)
|
2017-07-12 23:23:24 +03:00
|
|
|
|
{
|
2017-07-13 07:02:37 +03:00
|
|
|
|
_tapped = tappedAction;
|
|
|
|
|
Label.Text = attachment.Name;
|
2017-07-13 16:01:00 +03:00
|
|
|
|
Detail.Text = attachment.SizeName;
|
|
|
|
|
Icon.Source = "download";
|
2017-07-12 23:23:24 +03:00
|
|
|
|
BackgroundColor = Color.White;
|
2017-07-14 01:08:16 +03:00
|
|
|
|
Detail.MinimumWidthRequest = 100;
|
2017-07-13 17:51:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InitEvents()
|
|
|
|
|
{
|
2017-07-13 07:02:37 +03:00
|
|
|
|
Tapped += AttachmentViewCell_Tapped;
|
2017-07-12 23:23:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 17:51:45 +03:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Tapped -= AttachmentViewCell_Tapped;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-12 23:23:24 +03:00
|
|
|
|
private void AttachmentViewCell_Tapped(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-07-13 07:02:37 +03:00
|
|
|
|
_tapped?.Invoke();
|
2017-07-12 23:23:24 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
}
|