Exemplo n.º 1
0
        private async void Signup_Clicked(Object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(username.Text) && !string.IsNullOrEmpty(email.Text) && !string.IsNullOrEmpty(pass.Text) && !string.IsNullOrEmpty(conpass.Text))
            {
                if (string.Compare(pass.Text, conpass.Text) == 0)
                {
                    FirebaseAuthResponseModel res = new FirebaseAuthResponseModel()
                    {
                    };
                    res = await DependencyService.Get <iFirebaseAuth>().SignUpWithEmailPassword(username.Text, email.Text, pass.Text);

                    if (res.Status == true)
                    {
                        try
                        {
                            await CrossCloudFirestore.Current
                            .Instance
                            .GetCollection("users")
                            .GetDocument(dataClass.loggedInUser.uid)
                            .SetDataAsync(dataClass.loggedInUser);

                            await DisplayAlert("Success", res.Response, "Okay");

                            Application.Current.MainPage = new NavigationPage(new MainPage());
                        }
                        catch (Exception ex)
                        {
                            await DisplayAlert("Error", ex.Message, "Okay");
                        }
                    }
                    else
                    {
                        await DisplayAlert("Error", res.Response, "Okay");
                    }
                }
                else
                {
                    await DisplayAlert("Invalid Password", "Passwords do not match.", "Okay");
                }
            }
            else
            {
                await DisplayAlert("Missing Fields", "There are missing fields.", "Okay");
            }
        }
Exemplo n.º 2
0
        private async void Signin_CLicked(Object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(logemail.Text) && !string.IsNullOrEmpty(logpass.Text))
            {
                FirebaseAuthResponseModel res = new FirebaseAuthResponseModel()
                {
                };
                res = await DependencyService.Get <iFirebaseAuth>().LoginWithEmailPassword(logemail.Text, logpass.Text);

                if (res.Status == true)
                {
                    Application.Current.Properties["email"]      = dataClass.loggedInUser.email.ToString();
                    Application.Current.Properties["name"]       = dataClass.loggedInUser.name.ToString();
                    Application.Current.Properties["IsLoggedIn"] = DependencyService.Get <iFirebaseAuth>().IsLoggedIn().Status.ToString();
                    await Application.Current.SavePropertiesAsync();
                    await DisplayAlert("Successful", res.Response, "Okay");

                    Application.Current.MainPage = new NavigationPage(new TabbedPage1());
                }
                else
                {
                    bool retryBool = await DisplayAlert("Error", res.Response + " Retry?", "Yes", "No");

                    if (retryBool)
                    {
                        logemail.Text = string.Empty;
                        logpass.Text  = string.Empty;
                        logemail.Focus();
                    }
                }
            }
            else
            {
                await DisplayAlert("Missing Fields", "There are missing fields.", "Okay");

                logemail.Focus();
                logpass.Focus();
                if (logpass.IsFocused)
                {
                    logpass.BorderColor = Color.Red;
                }
            }
        }
        private async void ResetPassword_Clicked(Object sender, EventArgs e)
        {
            FirebaseAuthResponseModel res = new FirebaseAuthResponseModel()
            {
            };

            res = await DependencyService.Get <iFirebaseAuth>().ResetPassword(forgotemail.Text);

            if (res.Status == true)
            {
                await DisplayAlert("Success", res.Response, "Okay");

                await Navigation.PopModalAsync();

                Application.Current.MainPage = new NavigationPage(new MainPage());
            }
            else
            {
                await DisplayAlert("Error", res.Response, "Okay");
            }
        }
Exemplo n.º 4
0
        private async void LogoutButton_Clicked(object sender, EventArgs e)
        {
            FirebaseAuthResponseModel res = new FirebaseAuthResponseModel()
            {
            };

            res = DependencyService.Get <iFirebaseAuth>().SignOut();

            if (res.Status == true)
            {
                Application.Current.Properties.Remove("email");
                Application.Current.Properties.Remove("name");
                Application.Current.Properties.Remove("IsLoggedIn");
                await Application.Current.SavePropertiesAsync();

                Application.Current.MainPage = new NavigationPage(new MainPage());
            }
            else
            {
                await DisplayAlert("Error", res.Response, "Okay");
            }
        }