private async void Button_Login(object sender, Windows.UI.Xaml.RoutedEventArgs e) { System.Diagnostics.Debug.WriteLine(Email); System.Diagnostics.Debug.WriteLine(Passw); User u = await vm.Login(); System.Diagnostics.Debug.WriteLine(u.ID); if (u.Token != null) { MainPage mainPage = (Window.Current.Content as Frame).Content as MainPage; mainPage.DisplayNav(); Frame.Navigate(typeof(HolidayListPage)); } }
private async void BtnLogin_Clicked(object sender, EventArgs e) { Button button = (Button)sender; button.IsEnabled = false; try { var isVaild = ValidateUser(); if (isVaild) { var user = new User { networkStatus1 = UserNameEntry.Text, networkStatus2 = PasswordEntry.Text }; var res = await authViewModel.Login(user); if (res != null) { if (res.data.Code == 0) { App.IsUserLoggedIn = true; //storing token in secure storage try { await SecureStorage.SetAsync("auth_token", res.token); } catch (Exception ex) { // Possible that device doesn't support secure storage on device. } OperationData.userId = res.data.Data.userId; OperationData.userLocation = !string.IsNullOrEmpty(res.data.Data.userLocation) ? res.data.Data.userLocation : ""; OperationData.filterLocation = OperationData.userLocation; if (!res.data.Data.isProfileCompleted) { Application.Current.MainPage = new NavigationPage(new CompleteProfilePage(false, null)); } else { App.IsProfileCompleted = true; Application.Current.MainPage = new NavigationPage(new MainPage()); } //Application.Current.MainPage = new MainPage(); } else { await DisplayAlert("Message", "We could not log you in. Please try again", null, "OK"); } } else { await DisplayAlert("Message", "We could not log you in. Please try again", null, "OK"); } } bool ValidateUser() { bool areCredentialsCorrect = false; if (string.IsNullOrEmpty(UserNameEntry.Text)) { UserNameEntryInput.HasError = true; } else if (!string.IsNullOrEmpty(UserNameEntry.Text) && string.IsNullOrEmpty(PasswordEntry.Text)) { PasswordEntryInput.HasError = true; } else { UserNameEntry.Text = UserNameEntry.Text.Trim(); PasswordEntry.Text = PasswordEntry.Text.Trim(); areCredentialsCorrect = true; } return(areCredentialsCorrect); } } catch (Exception ex) { } finally { button.IsEnabled = true; } }