async Task ExecuteLoadItemsCommand() { IsBusy = true; if (!SecureStorageHelper.CheckIfUserSessionIsActive().Result) { App.Current.MainPage = new NavigationPage(new LoginPage()); } try { Items.Clear(); var items = await DataStore.GetSharedItems(true); foreach (var item in items) { Items.Add(item); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
private async void OnSendTokenClicked(object obj) { if (SecureStorageHelper.CheckIfUserSessionIsActive().Result) { App.Current.MainPage = new NavigationPage(new ItemsPage()); } if (string.IsNullOrEmpty(Token)) { MessagingCenter.Send(this, "AuthError", "Token cannot be empty."); return; } IsBusy = true; ApiTwoFactorResponse apiResponse = await _apiService.TwoFactorLogIn(await SecureStorageHelper.GetUserId(), Token); IsBusy = false; if (apiResponse.VerificationStatus != 1) { if (apiResponse.VerificationStatus == 0) { MessagingCenter.Send(this, "AuthError", apiResponse.Messages.First()); return; } else { MessagingCenter.Send(this, "AuthError", "Your code has expired. Try log in again."); SecureStorageHelper.ClearData(); await App.Current.MainPage.Navigation.PopModalAsync(); return; } } IsBusy = true; if (!_jwtHelper.ValidateToken(apiResponse.AccessToken, out _)) { // indicate errors MessagingCenter.Send(this, "AuthError", "Json web token is invalid"); await App.Current.MainPage.Navigation.PopModalAsync(); return; } await SecureStorageHelper.SaveUserData(apiResponse); //App.Current.MainPage.Navigation.InsertPageBefore(new ItemsPage(), TwoFactorPage); // await Navigation.PopAsync(); await App.Current.MainPage.Navigation.PopModalAsync(); IsBusy = false; App.Current.MainPage = new NavigationPage(new ItemsPage()); }
public App() { InitializeComponent(); DependencyService.Register <WebDataStore>(); DependencyService.Register <EncryptionService>(); if (SecureStorageHelper.CheckIfUserSessionIsActive().Result) { MainPage = new NavigationPage(new ItemsPage()); } else { MainPage = new NavigationPage(new LoginPage()); } }