From b3f2730c713a38da4893696135eb83a7c800bed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Bispo?= Date: Tue, 7 Jun 2022 18:44:07 +0100 Subject: [PATCH] PS-70 removed old authentication tab --- src/App/App.csproj | 1 - .../Authenticator/AuthenticatorPage.xaml | 97 ---------- .../Authenticator/AuthenticatorPage.xaml.cs | 176 ------------------ .../AuthenticatorPageListItem.cs | 129 ------------- .../AuthenticatorPageViewModel.cs | 153 --------------- src/App/Pages/TabsPage.cs | 8 - 6 files changed, 564 deletions(-) delete mode 100644 src/App/Pages/Authenticator/AuthenticatorPage.xaml delete mode 100644 src/App/Pages/Authenticator/AuthenticatorPage.xaml.cs delete mode 100644 src/App/Pages/Authenticator/AuthenticatorPageListItem.cs delete mode 100644 src/App/Pages/Authenticator/AuthenticatorPageViewModel.cs diff --git a/src/App/App.csproj b/src/App/App.csproj index 62aff81cc..2293da7e1 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -127,7 +127,6 @@ - diff --git a/src/App/Pages/Authenticator/AuthenticatorPage.xaml b/src/App/Pages/Authenticator/AuthenticatorPage.xaml deleted file mode 100644 index 9eb346a34..000000000 --- a/src/App/Pages/Authenticator/AuthenticatorPage.xaml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/App/Pages/Authenticator/AuthenticatorPage.xaml.cs b/src/App/Pages/Authenticator/AuthenticatorPage.xaml.cs deleted file mode 100644 index 2ca8971eb..000000000 --- a/src/App/Pages/Authenticator/AuthenticatorPage.xaml.cs +++ /dev/null @@ -1,176 +0,0 @@ -using Bit.App.Resources; -using System; -using System.Linq; -using System.Threading.Tasks; -using Bit.Core.Abstractions; -using Bit.Core.Utilities; -using Xamarin.Forms; -using Xamarin.Forms.PlatformConfiguration; -using Xamarin.Forms.PlatformConfiguration.iOSSpecific; - -namespace Bit.App.Pages -{ - public partial class AuthenticatorPage : BaseContentPage - { - #region Members - - private readonly IBroadcasterService _broadcasterService; - private readonly ISyncService _syncService; - private readonly ICipherService _cipherService; - private AuthenticatorPageViewModel _vm; - private readonly bool _fromTabPage; - private readonly Action _selectAction; - private readonly TabsPage _tabsPage; - - #endregion - - public AuthenticatorPage(bool fromTabPage, Action selectAction = null, TabsPage tabsPage = null) - { - //_tabsPage = tabsPage; - InitializeComponent(); - //_broadcasterService = ServiceContainer.Resolve("broadcasterService"); - _syncService = ServiceContainer.Resolve("syncService"); - _cipherService = ServiceContainer.Resolve("cipherService"); - _vm = BindingContext as AuthenticatorPageViewModel; - //_vm.Page = this; - //_fromTabPage = fromTabPage; - //_selectAction = selectAction; - - if (Device.RuntimePlatform == Device.iOS) - { - _absLayout.Children.Remove(_fab); - ToolbarItems.Add(_aboutIconItem); - ToolbarItems.Add(_addItem); - } - else - { - ToolbarItems.Add(_syncItem); - ToolbarItems.Add(_lockItem); - ToolbarItems.Add(_aboutTextItem); - } - } - - public async Task InitAsync() - { - await _vm.LoadAsync(); - } - - protected async override void OnAppearing() - { - base.OnAppearing(); - //if (!_fromTabPage) - //{ - // await InitAsync(); - //} - //_broadcasterService.Subscribe(nameof(GeneratorPage), async (message) => - //{ - // if (message.Command == "updatedTheme") - // { - // Device.BeginInvokeOnMainThread(() => - // { - // //_vm.RedrawPassword(); - // }); - // } - //}); - - await LoadOnAppearedAsync(_mainLayout, false, async () => - { - if (!_syncService.SyncInProgress || (await _cipherService.GetAllAsync()).Any()) - { - try - { - await _vm.LoadAsync(); - } - catch (Exception e) when (e.Message.Contains("No key.")) - { - await Task.Delay(1000); - await _vm.LoadAsync(); - } - } - else - { - await Task.Delay(5000); - if (!_vm.Loaded) - { - await _vm.LoadAsync(); - } - } - - AdjustToolbar(); - //await CheckAddRequest(); - }, _mainContent); - - } - - - - private async void Search_Clicked(object sender, EventArgs e) - { - if (DoOnce()) - { - // var page = new SendsPage(_vm.Filter, _vm.Type != null); - // await Navigation.PushModalAsync(new NavigationPage(page)); - } - } - - private async void Sync_Clicked(object sender, EventArgs e) - { - // await _vm.SyncAsync(); - } - - private async void Lock_Clicked(object sender, EventArgs e) - { - // await _vaultTimeoutService.LockAsync(true, true); - } - - private void About_Clicked(object sender, EventArgs e) - { - // _vm.ShowAbout(); - } - - private async void AddButton_Clicked(object sender, EventArgs e) - { - if (DoOnce()) - { - // var page = new SendAddEditPage(null, null, _vm.Type); - // await Navigation.PushModalAsync(new NavigationPage(page)); - } - } - - private async void RowSelected(object sender, SelectionChangedEventArgs e) - { - } - - private async void Copy_Clicked(object sender, EventArgs e) - { - //await _vm.CopyAsync(); - } - - private async void More_Clicked(object sender, EventArgs e) - { - //if (!DoOnce()) - //{ - // return; - //} - //var selection = await DisplayActionSheet(AppResources.Options, AppResources.Cancel, - // null, AppResources.PasswordHistory); - //if (selection == AppResources.PasswordHistory) - //{ - // var page = new GeneratorHistoryPage(); - // await Navigation.PushModalAsync(new Xamarin.Forms.NavigationPage(page)); - //} - } - - protected override void OnDisappearing() - { - base.OnDisappearing(); - //_broadcasterService.Unsubscribe(nameof(GeneratorPage)); - } - - private void AdjustToolbar() - { - //_addItem.IsEnabled = !_vm.Deleted; - //_addItem.IconImageSource = _vm.Deleted ? null : "plus.png"; - } - } -} diff --git a/src/App/Pages/Authenticator/AuthenticatorPageListItem.cs b/src/App/Pages/Authenticator/AuthenticatorPageListItem.cs deleted file mode 100644 index 5475a9a90..000000000 --- a/src/App/Pages/Authenticator/AuthenticatorPageListItem.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System.Threading.Tasks; -using Bit.App.Resources; -using Bit.App.Utilities; -using Bit.Core; -using Bit.Core.Abstractions; -using Bit.Core.Enums; -using Bit.Core.Models.View; -using Bit.Core.Utilities; -using Xamarin.Forms; - -namespace Bit.App.Pages -{ - public class AuthenticatorPageListItem : ExtendedViewModel - { - //private string _totpCode; - private readonly ITotpService _totpService; - - //public CipherView Cipher { get; set; } - //public CipherType? Type { get; set; } - //public int interval { get; set; } - //public long TotpSec { get; set; } - //private DateTime? _totpInterval = null; - - private CipherView _cipher; - - private bool _websiteIconsEnabled; - private string _iconImageSource = string.Empty; - - public int interval { get; set; } - private string _totpSec; - - private string _totpCode; - private string _totpCodeFormatted = "938 928"; - - - public AuthenticatorPageListItem(CipherView cipherView, bool websiteIconsEnabled) - { - _totpService = ServiceContainer.Resolve("totpService"); - - Cipher = cipherView; - WebsiteIconsEnabled = websiteIconsEnabled; - interval = _totpService.GetTimeInterval(Cipher.Login.Totp); - } - - - public Command CopyCommand { get; set; } - - public CipherView Cipher - { - get => _cipher; - set => SetProperty(ref _cipher, value); - } - - public string TotpCodeFormatted - { - get => _totpCodeFormatted; - set => SetProperty(ref _totpCodeFormatted, value); - } - - public string TotpSec - { - get => _totpSec; - set => SetProperty(ref _totpSec, value); - } - - public bool WebsiteIconsEnabled - { - get => _websiteIconsEnabled; - set => SetProperty(ref _websiteIconsEnabled, value); - } - - public bool ShowIconImage - { - get => WebsiteIconsEnabled - && !string.IsNullOrWhiteSpace(Cipher.Login?.Uri) - && IconImageSource != null; - } - - public string IconImageSource - { - get - { - if (_iconImageSource == string.Empty) // default value since icon source can return null - { - _iconImageSource = IconImageHelper.GetLoginIconImage(Cipher); - } - return _iconImageSource; - } - - } - - public async Task TotpTickAsync() - { - var epoc = CoreHelpers.EpocUtcNow() / 1000; - var mod = epoc % interval; - var totpSec = interval - mod; - TotpSec = totpSec.ToString(); - //TotpLow = totpSec < 7; - if (mod == 0) - { - await TotpUpdateCodeAsync(); - } - - } - - public async Task TotpUpdateCodeAsync() - { - _totpCode = await _totpService.GetCodeAsync(Cipher.Login.Totp); - if (_totpCode != null) - { - if (_totpCode.Length > 4) - { - var half = (int)Math.Floor(_totpCode.Length / 2M); - TotpCodeFormatted = string.Format("{0} {1}", _totpCode.Substring(0, half), - _totpCode.Substring(half)); - } - else - { - TotpCodeFormatted = _totpCode; - } - } - else - { - TotpCodeFormatted = null; - } - } - } -} diff --git a/src/App/Pages/Authenticator/AuthenticatorPageViewModel.cs b/src/App/Pages/Authenticator/AuthenticatorPageViewModel.cs deleted file mode 100644 index ffda90d0b..000000000 --- a/src/App/Pages/Authenticator/AuthenticatorPageViewModel.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System; -using System.Threading.Tasks; -using System.Linq; -using Bit.App.Resources; -using Bit.Core.Abstractions; -using Bit.Core.Models.View; -using Bit.Core.Utilities; -using Xamarin.Forms; - -namespace Bit.App.Pages -{ - public class AuthenticatorPageViewModel : BaseViewModel - { - #region Members - - private readonly IClipboardService _clipboardService; - private readonly ITotpService _totpService; - private readonly IUserService _userService; - private readonly IVaultTimeoutService _vaultTimeoutService; - private readonly ICipherService _cipherService; - - private bool _showList = true; - private bool _refreshing; - private bool _loaded; - private bool _websiteIconsEnabled = true; - //private long _totpSec; - #endregion - - #region Ctor - - public AuthenticatorPageViewModel() - { - _cipherService = ServiceContainer.Resolve("cipherService"); - _userService = ServiceContainer.Resolve("userService"); - _vaultTimeoutService = ServiceContainer.Resolve("vaultTimeoutService"); - _totpService = ServiceContainer.Resolve("totpService"); - - PageTitle = AppResources.Authenticator; - Items = new ExtendedObservableCollection(); - } - - #endregion - - #region Methods - - public async Task CopyAsync() - { - //await _clipboardService.CopyTextAsync(Password); - //_platformUtilsService.ShowToast("success", null, - // string.Format(AppResources.ValueHasBeenCopied, AppResources.Password)); - } - - public async Task LoadAsync() - { - var authed = await _userService.IsAuthenticatedAsync(); - if (!authed) - { - return; - } - if (await _vaultTimeoutService.IsLockedAsync()) - { - return; - } - - try - { - await LoadDataAsync(); - } - finally - { - ShowList = true; - Refreshing = false; - } - } - - private async Task LoadDataAsync() - { - var _allCiphers = await _cipherService.GetAllDecryptedAsync(); - _allCiphers = _allCiphers.Where(c => c.Type == Core.Enums.CipherType.Login && c.Login.Totp != null).ToList(); - var filteredCiphers = _allCiphers.Select(c => new AuthenticatorPageListItem(c, WebsiteIconsEnabled)).ToList(); - Items.ResetWithRange(filteredCiphers); - - foreach (AuthenticatorPageListItem item in Items) - { - item.TotpUpdateCodeAsync(); - } - - //await TotpUpdateCodeAsync(); - // var interval = _totpService.GetTimeInterval(Cipher.Login.Totp); - // await TotpTickAsync(interval); - // _totpInterval = DateTime.UtcNow; - Device.StartTimer(new TimeSpan(0, 0, 1), () => - { - foreach(AuthenticatorPageListItem item in Items) - { - item.TotpTickAsync(); - } - return true; - }); - //} - - //private async Task TotpTickAsync(int intervalSeconds) - //{ - // var epoc = CoreHelpers.EpocUtcNow() / 1000; - // var mod = epoc % intervalSeconds; - // var totpSec = intervalSeconds - mod; - // TotpSec = totpSec.ToString(); - // TotpLow = totpSec < 7; - // if (mod == 0) - // { - // await TotpUpdateCodeAsync(); - // } - } - - #endregion - - #region Properties - - public ExtendedObservableCollection Items { get; set; } - public Command RefreshCommand { get; set; } - - public bool ShowList - { - get => _showList; - set => SetProperty(ref _showList, value); - } - - public bool Refreshing - { - get => _refreshing; - set => SetProperty(ref _refreshing, value); - } - - public bool WebsiteIconsEnabled - { - get => _websiteIconsEnabled; - set => SetProperty(ref _websiteIconsEnabled, value); - } - - public bool Loaded - { - get => _loaded; - set => SetProperty(ref _loaded, value); - } - //public long TotpSec - //{ - // get => _totpSec; - // set => SetProperty(ref _totpSec, value); - //} - - #endregion - } -} diff --git a/src/App/Pages/TabsPage.cs b/src/App/Pages/TabsPage.cs index 568b7d59b..faeb69e0a 100644 --- a/src/App/Pages/TabsPage.cs +++ b/src/App/Pages/TabsPage.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using Bit.App.Effects; using Bit.App.Models; -using Bit.App.Pages.Authenticator; using Bit.App.Resources; using Bit.Core.Abstractions; using Bit.Core.Models.Data; @@ -37,13 +36,6 @@ namespace Bit.App.Pages Children.Add(_groupingsPage); - _authenticatorPage = new NavigationPage(new AuthenticatorPage(true, null, this)) - { - Title = AppResources.Authenticator, - IconImageSource = "info.png" - }; - Children.Add(_authenticatorPage); - _sendGroupingsPage = new NavigationPage(new SendGroupingsPage(true, null, null, appOptions)) { Title = AppResources.Send,