[Autofill] Apply locked autofill flow to logged out state (#827)

* Initial commit: apply locked auto-fill flow to log out auto-fill

* Alphabetized imports

* Removed unnecessary else conditional

* Fix for talkback slider control (#828)

* Initial commit: apply locked auto-fill flow to log out auto-fill

* Alphabetized imports

* Removed unnecessary else conditional

* Fixed variable init order

Co-authored-by: Matt Portune <59324545+mportune-bw@users.noreply.github.com>
This commit is contained in:
Vincent Salucci 2020-04-13 11:32:23 -05:00 committed by GitHub
parent b2abcda111
commit 1dc027cf49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 13 deletions

View File

@ -304,7 +304,7 @@ namespace Bit.App
}
else
{
Current.MainPage = new HomePage();
Current.MainPage = new HomePage(_appOptions);
}
}

View File

@ -1,4 +1,5 @@
using Bit.App.Utilities;
using Bit.App.Models;
using Bit.App.Utilities;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
using System;
@ -9,12 +10,14 @@ namespace Bit.App.Pages
{
public partial class HomePage : BaseContentPage
{
private readonly AppOptions _appOptions;
private IMessagingService _messagingService;
public HomePage()
public HomePage(AppOptions appOptions = null)
{
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
_messagingService.Send("showStatusBar", false);
_appOptions = appOptions;
InitializeComponent();
_logo.Source = !ThemeManager.UsingLightTheme ? "logo_white.png" : "logo.png";
}
@ -22,7 +25,7 @@ namespace Bit.App.Pages
public async Task DismissRegisterPageAndLogInAsync(string email)
{
await Navigation.PopModalAsync();
await Navigation.PushModalAsync(new NavigationPage(new LoginPage(email)));
await Navigation.PushModalAsync(new NavigationPage(new LoginPage(email, _appOptions)));
}
protected override void OnAppearing()
@ -35,7 +38,7 @@ namespace Bit.App.Pages
{
if (DoOnce())
{
Navigation.PushModalAsync(new NavigationPage(new LoginPage()));
Navigation.PushModalAsync(new NavigationPage(new LoginPage(null, _appOptions)));
}
}

View File

@ -106,7 +106,7 @@ namespace Bit.App.Pages
Application.Current.MainPage = new NavigationPage(new AddEditPage(appOptions: _appOptions));
return;
}
else if (_appOptions.Uri != null)
if (_appOptions.Uri != null)
{
Application.Current.MainPage = new NavigationPage(new AutofillCiphersPage(_appOptions));
return;

View File

@ -1,6 +1,9 @@
using Bit.Core.Abstractions;
using Bit.App.Models;
using Bit.Core;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
using System;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Bit.App.Pages
@ -8,15 +11,21 @@ namespace Bit.App.Pages
public partial class LoginPage : BaseContentPage
{
private readonly IMessagingService _messagingService;
private readonly IStorageService _storageService;
private readonly LoginPageViewModel _vm;
private readonly AppOptions _appOptions;
public LoginPage(string email = null)
public LoginPage(string email = null, AppOptions appOptions = null)
{
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
_messagingService.Send("showStatusBar", true);
_appOptions = appOptions;
InitializeComponent();
_vm = BindingContext as LoginPageViewModel;
_vm.Page = this;
_vm.StartTwoFactorAction = () => Device.BeginInvokeOnMainThread(async () => await StartTwoFactorAsync());
_vm.LoggedInAction = () => Device.BeginInvokeOnMainThread(async () => await LoggedInAsync());
_vm.Email = email;
MasterPasswordEntry = _masterPassword;
if (Device.RuntimePlatform == Device.Android)
@ -68,5 +77,34 @@ namespace Bit.App.Pages
await Navigation.PopModalAsync();
}
}
private async Task StartTwoFactorAsync()
{
var page = new TwoFactorPage();
await Navigation.PushModalAsync(new NavigationPage(page));
}
private async Task LoggedInAsync()
{
if (_appOptions != null)
{
if (_appOptions.FromAutofillFramework && _appOptions.SaveType.HasValue)
{
Application.Current.MainPage = new NavigationPage(new AddEditPage(appOptions: _appOptions));
return;
}
if (_appOptions.Uri != null)
{
Application.Current.MainPage = new NavigationPage(new AutofillCiphersPage(_appOptions));
return;
}
}
var previousPage = await _storageService.GetAsync<PreviousPageInfo>(Constants.PreviousPageKey);
if (previousPage != null)
{
await _storageService.RemoveAsync(Constants.PreviousPageKey);
}
Application.Current.MainPage = new TabsPage(_appOptions, previousPage);
}
}
}

View File

@ -4,6 +4,7 @@ using Bit.Core;
using Bit.Core.Abstractions;
using Bit.Core.Exceptions;
using Bit.Core.Utilities;
using System;
using System.Threading.Tasks;
using Xamarin.Forms;
@ -65,6 +66,8 @@ namespace Bit.App.Pages
public Command TogglePasswordCommand { get; }
public string ShowPasswordIcon => ShowPassword ? "" : "";
public bool RememberEmail { get; set; }
public Action StartTwoFactorAction { get; set; }
public Action LoggedInAction { get; set; }
public async Task InitAsync()
{
@ -121,15 +124,14 @@ namespace Bit.App.Pages
await _deviceActionService.HideLoadingAsync();
if (response.TwoFactor)
{
var page = new TwoFactorPage();
await Page.Navigation.PushModalAsync(new NavigationPage(page));
StartTwoFactorAction?.Invoke();
}
else
{
var disableFavicon = await _storageService.GetAsync<bool?>(Constants.DisableFaviconKey);
await _stateService.SaveAsync(Constants.DisableFaviconKey, disableFavicon.GetValueOrDefault());
var task = Task.Run(async () => await _syncService.FullSyncAsync(true));
Application.Current.MainPage = new TabsPage();
LoggedInAction?.Invoke();
}
}
catch (ApiException e)

View File

@ -1,4 +1,6 @@
using Bit.App.Controls;
using Bit.App.Models;
using Bit.Core;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
using System;
@ -11,18 +13,23 @@ namespace Bit.App.Pages
{
private readonly IBroadcasterService _broadcasterService;
private readonly IMessagingService _messagingService;
private readonly IStorageService _storageService;
private readonly AppOptions _appOptions;
private TwoFactorPageViewModel _vm;
private bool _inited;
public TwoFactorPage()
public TwoFactorPage(AppOptions appOptions = null)
{
InitializeComponent();
SetActivityIndicator();
_appOptions = appOptions;
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
_messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
_vm = BindingContext as TwoFactorPageViewModel;
_vm.Page = this;
_vm.TwoFactorAction = () => Device.BeginInvokeOnMainThread(async () => await TwoFactorAuthAsync());
DuoWebView = _duoWebView;
if (Device.RuntimePlatform == Device.Android)
{
@ -151,5 +158,28 @@ namespace Bit.App.Pages
}
}
}
private async Task TwoFactorAuthAsync()
{
if (_appOptions != null)
{
if (_appOptions.FromAutofillFramework && _appOptions.SaveType.HasValue)
{
Application.Current.MainPage = new NavigationPage(new AddEditPage(appOptions: _appOptions));
return;
}
if (_appOptions.Uri != null)
{
Application.Current.MainPage = new NavigationPage(new AutofillCiphersPage(_appOptions));
return;
}
}
var previousPage = await _storageService.GetAsync<PreviousPageInfo>(Constants.PreviousPageKey);
if (previousPage != null)
{
await _storageService.RemoveAsync(Constants.PreviousPageKey);
}
Application.Current.MainPage = new TabsPage(_appOptions, previousPage);
}
}
}

View File

@ -6,6 +6,7 @@ using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Models.Request;
using Bit.Core.Utilities;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
@ -88,6 +89,7 @@ namespace Bit.App.Pages
});
}
public Command SubmitCommand { get; }
public Action TwoFactorAction { get; set; }
public void Init()
{
@ -209,7 +211,7 @@ namespace Bit.App.Pages
_broadcasterService.Unsubscribe(nameof(TwoFactorPage));
var disableFavicon = await _storageService.GetAsync<bool?>(Constants.DisableFaviconKey);
await _stateService.SaveAsync(Constants.DisableFaviconKey, disableFavicon.GetValueOrDefault());
Application.Current.MainPage = new TabsPage();
TwoFactorAction?.Invoke();
}
catch (ApiException e)
{