public void SaveFacebookProfileAsyncFake()
        {
            if (!FromLogonPage)
            {
                if (FacebookEmail.ToLower().Trim() == TESTEMAIL1 || FacebookEmail.ToLower().Trim() == TESTEMAIL2 || FacebookEmail.ToLower().Trim() == TESTEMAIL3)
                {
                    SaveToDBAndNavigateToNextPage();
                    return;
                }

                if (IsEmailExisting().Result)
                {
                    RedirectToLogon().Wait();
                    return;
                }
                else
                {
                    SaveToDBAndNavigateToNextPage();
                }
            }
            else
            {
                IsBusy = true;
                GetLogonDetailsFromRemoteDBAsyncFake();
            }
        }
Exemple #2
0
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error     -= OnAuthError;
            }


            if (e.IsAuthenticated)
            {
                if (authenticator.AuthorizeUrl.Host == "www.facebook.com")
                {
                    FacebookEmail facebookEmail = null;



                    var httpClient = new HttpClient();

                    var json = await httpClient.GetStringAsync($"https://graph.facebook.com/me?fields=id,name,first_name,last_name,email,picture.type(large)&access_token=" + e.Account.Properties["access_token"]);

                    facebookEmail = JsonConvert.DeserializeObject <FacebookEmail>(json);

                    await store.SaveAsync(account = e.Account, Constants.AppName);

                    Application.Current.Properties["IsLoggedIn"] = Boolean.TrueString;

                    bool newuser = false;
                    if (await FirebaseHelper.CheckFacebookEmail(facebookEmail.Email) == false)
                    {
                        await FirebaseHelper.AddFacebookUser(facebookEmail.Id, facebookEmail.Name, facebookEmail.First_Name, facebookEmail.Last_Name, facebookEmail.Email, facebookEmail.Picture);

                        newuser = true;
                    }

                    Application.Current.Properties.Remove("Id");
                    Application.Current.Properties.Remove("FirstName");
                    Application.Current.Properties.Remove("LastName");
                    Application.Current.Properties.Remove("DisplayName");
                    Application.Current.Properties.Remove("EmailAddress");
                    Application.Current.Properties.Remove("ProfilePicture");

                    Application.Current.Properties.Add("Id", facebookEmail.Id);
                    Application.Current.Properties.Add("FirstName", facebookEmail.First_Name);
                    Application.Current.Properties.Add("LastName", facebookEmail.Last_Name);
                    Application.Current.Properties.Add("DisplayName", facebookEmail.Name);
                    Application.Current.Properties.Add("EmailAddress", facebookEmail.Email);
                    Application.Current.Properties.Add("ProfilePicture", facebookEmail.Picture.Data.Url);

                    if (newuser)
                    {
                        await FirebaseHelper.AddPantryItem("Example Item", "5", "12/15");
                    }
                    App.Current.MainPage = new AppShell();
                }
            }
        }
        private void FacebookAuth_CompletedAsync(object sender, AuthenticatorCompletedEventArgs e)
        {
            if (e.IsAuthenticated)
            {
                //ShowLoading.Show(this, setColorFilterr: true);
                new System.Threading.Thread(new System.Threading.ThreadStart(delegate
                {
                    var authenticator = sender as OAuth2Authenticator;
                    if (authenticator.AuthorizeUrl.Host == "m.facebook.com")
                    {
                        WebService webService = new WebService();
                        var FacebookDonus     = webService.OkuGetir($"https://graph.facebook.com/me?fields=id,name,first_name,last_name,email,picture.type(large)&access_token=" + e.Account.Properties["access_token"], true, true);
                        if (FacebookDonus != null)
                        {
                            var Durum     = FacebookDonus.ToString();
                            facebookEmail = JsonConvert.DeserializeObject <FacebookEmail>(FacebookDonus);

                            #region FaceBook Login With Out API
                            string Ad   = "", Soyad = "", email, sifre;
                            var parcala = facebookEmail.Name.Split(' ');
                            for (int i = 0; i < parcala.Length; i++)
                            {
                                if (i == 0)
                                {
                                    Ad = parcala[0];
                                }
                                else
                                {
                                    Soyad += parcala[1];
                                }
                            }
                            email = facebookEmail.Email;
                            sifre = facebookEmail.Id;

                            if (GirisYapmayiDene(email, sifre))//Önce giriş yapmayı dene
                            {
                                this.StartActivity(typeof(Splash));
                                this.Finish();
                            }
                            else//Yapamazsan Kayit olmayı dene
                            {
                                if (KayitOl(email, sifre, Ad, Soyad))//Kayıt olursan tekrar giriş yapmayı dene
                                {
                                    if (GirisYapmayiDene(email, sifre))
                                    {
                                        this.StartActivity(typeof(Splash));
                                        this.Finish();
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                })).Start();
            }
        }
Exemple #4
0
        private void Auth_Completed(object sender, AuthenticatorCompletedEventArgs e)
        {
            if (e.IsAuthenticated)
            {
                FacebookVC.DismissViewController(true, null);
                //CustomAlert.GetCustomAlert(this, "Lütfen Bekleyin...");
                new System.Threading.Thread(new System.Threading.ThreadStart(delegate
                {
                    var authenticator = sender as OAuth2Authenticator;
                    if (authenticator.AuthorizeUrl.Host == "m.facebook.com")
                    {
                        FacebookEmail facebookEmail = null;

                        WebService webService = new WebService();
                        var FacebookDonus     = webService.OkuGetir($"https://graph.facebook.com/me?fields=id,name,first_name,last_name,email,picture.type(large)&access_token=" + e.Account.Properties["access_token"], true);
                        if (FacebookDonus != null)
                        {
                            var Durum     = FacebookDonus.ToString();
                            facebookEmail = JsonConvert.DeserializeObject <FacebookEmail>(FacebookDonus.ToString());

                            #region FaceBook Login With Out API
                            string Ad   = "", Soyad = "", email, sifre;
                            var parcala = facebookEmail.name.Split(' ');
                            for (int i = 0; i < parcala.Length; i++)
                            {
                                if (i == 0)
                                {
                                    Ad = parcala[0];
                                }
                                else
                                {
                                    Soyad += parcala[1];
                                }
                            }
                            email = facebookEmail.email;
                            sifre = "Buptis2019@@";
                            SosyalKullaniciKaydet(Ad, Soyad, sifre, email);
                            #endregion
                        }
                    }
                })).Start();
            }
        }
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error     -= OnAuthError;
            }

            if (e.IsAuthenticated)
            {
                if (authenticator.AuthorizeUrl.Host == "www.facebook.com")
                {
                    FacebookEmail facebookEmail = null;

                    var httpClient = new HttpClient();
                    var json       = await httpClient.GetStringAsync($"https://graph.facebook.com/me?fields=id,name,first_name,last_name,email,picture.type(large)&access_token=" + e.Account.Properties["access_token"]);

                    facebookEmail = JsonConvert.DeserializeObject <FacebookEmail>(json);
                    //await store.SaveAsync(account = e.Account, Constants.AppName);

                    try
                    {
                        await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName);
                    }
                    catch { }


                    Application.Current.Properties.Remove("Id");
                    Application.Current.Properties.Remove("FirstName");
                    Application.Current.Properties.Remove("LastName");
                    Application.Current.Properties.Remove("DisplayName");
                    Application.Current.Properties.Remove("EmailAddress");
                    Application.Current.Properties.Remove("ProfilePicture");
                    Application.Current.Properties.Add("Id", facebookEmail.Id);
                    Application.Current.Properties.Add("FirstName", facebookEmail.First_Name);
                    Application.Current.Properties.Add("LastName", facebookEmail.Last_Name);
                    Application.Current.Properties.Add("DisplayName", facebookEmail.Name);
                    Application.Current.Properties.Add("EmailAddress", facebookEmail.Email);
                    Application.Current.Properties.Add("ProfilePicture", facebookEmail.Picture.Data.Url);
                    //await Navigation.PushAsync(new ProfilePage());
                    //                    await NavigationService.NavigateTo(typeof(BikeDetailViewModel), string.Empty, string.Empty, true);
                    await NavigationService.NavigateToAsync <BikeDetailViewModel>();
                }
                else
                {
                    SocialMediaUser user = null;

                    // If the user is authenticated, request their basic user data from Google
                    // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo
                    var request  = new OAuth2Request("GET", new Uri(Constants.GoogleUserInfoUrl), null, e.Account);
                    var response = await request.GetResponseAsync();

                    if (response != null)
                    {
                        // Deserialize the data and store it in the account store

                        // The users email address will be used to identify data in SimpleDB

                        string userJson = await response.GetResponseTextAsync();

                        user = JsonConvert.DeserializeObject <SocialMediaUser>(userJson);
                    }

                    /*if (account != null)
                     * {
                     *  store.Delete(account, Constants.AppName);
                     * }
                     * await store.SaveAsync(account = e.Account, Constants.AppName); */

                    try
                    {
                        await SecureStorageAccountStore.SaveAsync(e.Account, Constants.AppName);
                    }
                    catch { }

                    Application.Current.Properties.Remove("Id");
                    Application.Current.Properties.Remove("FirstName");
                    Application.Current.Properties.Remove("LastName");
                    Application.Current.Properties.Remove("DisplayName");
                    Application.Current.Properties.Remove("EmailAddress");
                    Application.Current.Properties.Remove("ProfilePicture");
                    Application.Current.Properties.Add("Id", user.Id);
                    Application.Current.Properties.Add("FirstName", user.GivenName);
                    Application.Current.Properties.Add("LastName", user.FamilyName);
                    Application.Current.Properties.Add("DisplayName", user.Name);
                    Application.Current.Properties.Add("EmailAddress", user.Email);
                    Application.Current.Properties.Add("ProfilePicture", user.Picture);

                    //await Navigation.PushAsync(new ProfilePage());
                    await NavigationService.NavigateToAsync <BikeDetailViewModel>();

                    //                    await NavigationService.NavigateTo(typeof(BikeDetailViewModel), string.Empty, string.Empty, true);
                }
            }
        }
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            //ovalay.IsVisible = true;
            btnGoogle.Text      = "Authenticating...";
            btnGoogle.IsEnabled = false;
            var authenticator = sender as OAuth2Authenticator;

            if (authenticator != null)
            {
                authenticator.Completed -= OnAuthCompleted;
                authenticator.Error     -= OnAuthError;
            }


            if (e.IsAuthenticated)
            {
                if (authenticator.AuthorizeUrl.Host == "www.facebook.com")
                {
                    FacebookEmail facebookEmail = null;

                    var httpClient = new HttpClient();

                    var json = await httpClient.GetStringAsync($"https://graph.facebook.com/me?fields=id,name,first_name,last_name,email,picture.type(large)&access_token=" + e.Account.Properties["access_token"]);

                    facebookEmail = JsonConvert.DeserializeObject <FacebookEmail>(json);

                    await store.SaveAsync(account = e.Account, Constants.AppName);

                    Application.Current.Properties.Remove("Id");
                    Application.Current.Properties.Remove("FirstName");
                    Application.Current.Properties.Remove("LastName");
                    Application.Current.Properties.Remove("DisplayName");
                    Application.Current.Properties.Remove("EmailAddress");
                    Application.Current.Properties.Remove("ProfilePicture");

                    Application.Current.Properties.Add("Id", facebookEmail.Id);
                    Application.Current.Properties.Add("FirstName", facebookEmail.First_Name);
                    Application.Current.Properties.Add("LastName", facebookEmail.Last_Name);
                    Application.Current.Properties.Add("DisplayName", facebookEmail.Name);
                    Application.Current.Properties.Add("EmailAddress", facebookEmail.Email);
                    Application.Current.Properties.Add("ProfilePicture", facebookEmail.Picture.Data.Url);

                    Application.Current.MainPage = new AppShell();
                }
                else
                {
                    //User user = null;

                    // If the user is authenticated, request their basic user data from Google
                    // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo
                    var request  = new OAuth2Request("GET", new Uri(Constants.GoogleUserInfoUrl), null, e.Account);
                    var response = await request.GetResponseAsync();

                    if (response != null)
                    {
                        // Deserialize the data and store it in the account store
                        // The users email address will be used to identify data in SimpleDB
                        string userJson = await response.GetResponseTextAsync();

                        //user = JsonConvert.DeserializeObject<User>(userJson);
                        Preferences.Set("userData", userJson);
                        Debug.WriteLine("Authentication user info: " + userJson);
                    }

                    if (account != null)
                    {
                        store.Delete(account, Constants.AppName);
                    }

                    await store.SaveAsync(account = e.Account, Constants.AppName);

                    //Application.Current.Properties.Remove("Id");
                    //Application.Current.Properties.Remove("FirstName");
                    //Application.Current.Properties.Remove("LastName");
                    //Application.Current.Properties.Remove("DisplayName");
                    //Application.Current.Properties.Remove("EmailAddress");
                    //Application.Current.Properties.Remove("ProfilePicture");

                    //Application.Current.Properties.Add("Id", user.Id);
                    //Application.Current.Properties.Add("FirstName", user.GivenName);
                    //Application.Current.Properties.Add("LastName", user.FamilyName);
                    //Application.Current.Properties.Add("DisplayName", user.Name);
                    //Application.Current.Properties.Add("EmailAddress", user.Email);
                    //Application.Current.Properties.Add("ProfilePicture", user.Picture);

                    Application.Current.MainPage = new AppShell();
                }
            }
        }