diff --git a/src/App/Pages/Accounts/HomePage.xaml.cs b/src/App/Pages/Accounts/HomePage.xaml.cs index 9d4fc4d75..260bd62b9 100644 --- a/src/App/Pages/Accounts/HomePage.xaml.cs +++ b/src/App/Pages/Accounts/HomePage.xaml.cs @@ -1,5 +1,6 @@ using Bit.App.Utilities; using System; +using System.Threading.Tasks; using Xamarin.Forms; namespace Bit.App.Pages @@ -13,6 +14,12 @@ namespace Bit.App.Pages _logo.Source = theme == "dark" || theme == "black" ? "logo_white.png" : "logo.png"; } + public async Task DismissRegisterPageAndLogInAsync(string email) + { + await Navigation.PopModalAsync(); + await Navigation.PushModalAsync(new NavigationPage(new LoginPage(email))); + } + private void LogIn_Clicked(object sender, EventArgs e) { if(DoOnce()) @@ -25,7 +32,7 @@ namespace Bit.App.Pages { if(DoOnce()) { - Navigation.PushModalAsync(new NavigationPage(new RegisterPage())); + Navigation.PushModalAsync(new NavigationPage(new RegisterPage(this))); } } diff --git a/src/App/Pages/Accounts/LoginPage.xaml.cs b/src/App/Pages/Accounts/LoginPage.xaml.cs index a2627a10c..000a76e9a 100644 --- a/src/App/Pages/Accounts/LoginPage.xaml.cs +++ b/src/App/Pages/Accounts/LoginPage.xaml.cs @@ -7,11 +7,12 @@ namespace Bit.App.Pages { private LoginPageViewModel _vm; - public LoginPage() + public LoginPage(string email = null) { InitializeComponent(); _vm = BindingContext as LoginPageViewModel; _vm.Page = this; + _vm.Email = email; MasterPasswordEntry = _masterPassword; _email.ReturnType = ReturnType.Next; diff --git a/src/App/Pages/Accounts/RegisterPage.xaml.cs b/src/App/Pages/Accounts/RegisterPage.xaml.cs index 192165af4..e7c60dc13 100644 --- a/src/App/Pages/Accounts/RegisterPage.xaml.cs +++ b/src/App/Pages/Accounts/RegisterPage.xaml.cs @@ -7,11 +7,18 @@ namespace Bit.App.Pages { private RegisterPageViewModel _vm; - public RegisterPage() + public RegisterPage(HomePage homePage) { InitializeComponent(); _vm = BindingContext as RegisterPageViewModel; _vm.Page = this; + _vm.RegistrationSuccess = async () => + { + if(homePage != null) + { + await homePage.DismissRegisterPageAndLogInAsync(_vm.Email); + } + }; MasterPasswordEntry = _masterPassword; ConfirmMasterPasswordEntry = _confirmMasterPassword; diff --git a/src/App/Pages/Accounts/RegisterPageViewModel.cs b/src/App/Pages/Accounts/RegisterPageViewModel.cs index 24bc75f89..e0e712da9 100644 --- a/src/App/Pages/Accounts/RegisterPageViewModel.cs +++ b/src/App/Pages/Accounts/RegisterPageViewModel.cs @@ -5,6 +5,7 @@ using Bit.Core.Enums; using Bit.Core.Exceptions; using Bit.Core.Models.Request; using Bit.Core.Utilities; +using System; using System.Threading.Tasks; using Xamarin.Forms; @@ -16,7 +17,6 @@ namespace Bit.App.Pages private readonly IApiService _apiService; private readonly ICryptoService _cryptoService; private readonly IPlatformUtilsService _platformUtilsService; - private bool _showPassword; public RegisterPageViewModel() @@ -26,7 +26,7 @@ namespace Bit.App.Pages _cryptoService = ServiceContainer.Resolve("cryptoService"); _platformUtilsService = ServiceContainer.Resolve("platformUtilsService"); - PageTitle = AppResources.Bitwarden; + PageTitle = AppResources.CreateAccount; TogglePasswordCommand = new Command(TogglePassword); ToggleConfirmPasswordCommand = new Command(ToggleConfirmPassword); SubmitCommand = new Command(async () => await SubmitAsync()); @@ -51,6 +51,7 @@ namespace Bit.App.Pages public string MasterPassword { get; set; } public string ConfirmMasterPassword { get; set; } public string Hint { get; set; } + public Action RegistrationSuccess { get; set; } public async Task SubmitAsync() { @@ -121,10 +122,15 @@ namespace Bit.App.Pages try { - await _deviceActionService.ShowLoadingAsync(AppResources.LoggingIn); + await _deviceActionService.ShowLoadingAsync(AppResources.CreatingAccount); await _apiService.PostRegisterAsync(request); await _deviceActionService.HideLoadingAsync(); - // TODO: dismiss this page from home page and pass email for login page + _platformUtilsService.ShowToast("success", null, AppResources.AccountCreated, + new System.Collections.Generic.Dictionary + { + ["longDuration"] = true + }); + RegistrationSuccess?.Invoke(); } catch(ApiException e) {