Example #1
0
        private async void TripBookedSuccess(object sender, EventArgs e)
        {
            await FirebaseFirestoreHelper.CreateTrip(App.UserEmail, App.UserName, "", viewModel.PickupLocation, viewModel.DestinationLocation, viewModel.TripDateAndTime.ToUniversalTime(), DateTime.UtcNow, 200, viewModel.messageForDriver, viewModel.SelectedRideOption.RideName);

            await Navigation.PopPopupAsync();

            await Shell.Current.Navigation.PushAsync(new TripBookedSuccess());
        }
        private async void SignIn_Clicked(object sender, EventArgs e)
        {
            if (email.Text?.Length > 0 && password.Text?.Length > 0)
            {
                IsBusy.IsVisible = true;
                IsBusy.IsRunning = true;
                try
                {
                    App.FirebaseToken = await DependencyService.Get <IFirebaseAuthenticator>().LoginWithEmailPassword(email.Text.Trim().ToLower(), password.Text);

                    FirebaseUser userInfo = await FirebaseFirestoreHelper.GetUserInfo(email.Text.Trim().ToLower());

                    await Xamarin.Essentials.SecureStorage.SetAsync("isLogged", "1");

                    await Xamarin.Essentials.SecureStorage.SetAsync("UserEmail", email.Text.Trim().ToLower());

                    App.UserEmail = email.Text.Trim();
                    await Xamarin.Essentials.SecureStorage.SetAsync("PaymentId", userInfo.PaymentId);

                    App.PaymentId = userInfo.PaymentId;
                    await Xamarin.Essentials.SecureStorage.SetAsync("UserName", userInfo.Username);

                    App.UserName     = userInfo.Username;
                    IsBusy.IsVisible = false;
                    IsBusy.IsRunning = false;
                    Xamarin.Forms.Application.Current.MainPage = new AppShell();
                    await Shell.Current.GoToAsync("//main");
                }
                catch (Exception ex)
                {
                    IsBusy.IsVisible = false;
                    IsBusy.IsRunning = false;
                    DependencyService.Get <IFirebaseAuthenticator>().SignOut();
                    Xamarin.Essentials.SecureStorage.RemoveAll();
                    if (ex.GetType().ToString() == "Firebase.Auth.FirebaseAuthInvalidUserException")
                    {
                        await DisplayAlert("Oops", "We didn't find any user with that Email. Please register for a new Account", "Ok");
                    }
                    else if (ex.GetType().ToString() == "Firebase.Auth.FirebaseAuthInvalidCredentialsException")
                    {
                        await DisplayAlert("Oops", "Invalid Email/Password Combination. Please try again", "Ok");
                    }
                    else
                    {
                        await DisplayAlert("Oops", "Something went wrong. Please try again.", "Ok");
                    }
                }
            }
            else
            {
                await DisplayAlert("Oops", "Please enter your Email and Password", "Ok");
            }
        }
        private async void registerNewAccount(object sender, EventArgs e)
        {
            if (name.Text?.Length > 0 && email.Text?.Length > 0 && password.Text?.Length > 0)
            {
                try
                {
                    string token = await DependencyService.Get <IFirebaseAuthenticator>()
                                   .SignUpWithEmailPassword(email.Text, password.Text, name.Text, isDriver.IsChecked);

                    string paymentId = PaymentHelper.CreateNewCustomer(email.Text.Trim());
                    await FirebaseFirestoreHelper.AddUserInfo(name.Text.Trim(), email.Text.Trim().ToLower(), isDriver.IsChecked, paymentId);

                    await Xamarin.Essentials.SecureStorage.SetAsync("isLogged", "1");

                    await Xamarin.Essentials.SecureStorage.SetAsync("UserEmail", email.Text.Trim());

                    App.UserEmail = email.Text.Trim();
                    await Xamarin.Essentials.SecureStorage.SetAsync("PaymentId", paymentId);

                    App.PaymentId = paymentId;
                    await Xamarin.Essentials.SecureStorage.SetAsync("UserName", name.Text.Trim());

                    App.UserName = name.Text.Trim();
                    Xamarin.Forms.Application.Current.MainPage = new AppShell();
                    await Shell.Current.GoToAsync("//main");
                }
                catch (Exception ex)
                {
                    if (ex.GetType().ToString() == "Firebase.Auth.FirebaseAuthInvalidCredentialsException")
                    {
                        await DisplayAlert("Oops", "Please check the Email is correct", "Ok");
                    }
                    else if (ex.GetType().ToString() == "Firebase.Auth.FirebaseAuthWeakPasswordException")
                    {
                        await DisplayAlert("Oops", "The password doesn't meet the minimum security requirements. Please re-enter a stronger Password", "Ok");
                    }
                    else if (ex.GetType().ToString() == "Firebase.Auth.FirebaseAuthUserCollisionException")
                    {
                        await DisplayAlert("Oops", "The entered Email has already been used before. Try logging in or resetting the password.", "Ok");
                    }
                    else
                    {
                        await DisplayAlert("Oops", "Something went wrong. Please try again.", "Ok");
                    }
                }
            }
            else
            {
                await DisplayAlert("Oops", "Some of the fields have not been filled in.", "Ok");
            }
        }
Example #4
0
 Task <List <UserTrip> > GetTripsAsync()
 {
     return(FirebaseFirestoreHelper.GetTrips());
 }