Beispiel #1
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();
                }
            }
        }
Beispiel #2
0
        public static async Task <bool> CheckFacebookEmail(string email)
        {
            bool accountFound = false;
            await FirebaseHelper.GetAllFacebookUsers().ContinueWith(t =>
            {
                List <FacebookEmail> userCheck = (t.Result);
                if (userCheck.Find(x => x.Email.Contains(email)) != null)
                {
                    accountFound = true;
                }
            });

            return(accountFound);
        }
        private async void AddShoppingList()
        {
            if (string.IsNullOrEmpty(ItemName) || string.IsNullOrEmpty(Amount.ToString()))
            {
                await App.Current.MainPage.DisplayAlert("Empty Values", "Please enter Item Name and Quantity.", "Ok");
            }
            else
            {
                var shoppingList = await FirebaseHelper.AddShoppingList(ItemName, Amount);

                if (shoppingList)
                {
                    await RefreshList();
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Couldn't Add Item", "Please Try Again", "OK");
                }
            }
        }
Beispiel #4
0
        private async void AddPantry()
        {
            if (string.IsNullOrEmpty(ItemName) || string.IsNullOrEmpty(Quantity) || string.IsNullOrEmpty(ExpirationDate))
            {
                await App.Current.MainPage.DisplayAlert("Empty Values", "Please enter Item Name, Calories, and Quantity.", "OK");
            }
            else
            {
                var user = await FirebaseHelper.AddPantryItem(ItemName, Quantity, ExpirationDate);

                if (user)
                {
                    await App.Current.MainPage.DisplayAlert("Item Added!", "", "OK");
                    await RefreshPantry();
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Couldn't Add Item", "Please Try Again", "OK");
                }
            }
        }
Beispiel #5
0
        async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e)
        {
            var authenticator = sender as OAuth2Authenticator;

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

            GoogleUsers user = null;

            if (e.IsAuthenticated)
            {
                // 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.UserInfoUrl), 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 <GoogleUsers>(userJson);
                    user.IsToggled  = false;
                    user.IsLoggedIn = true;
                }


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



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


                bool newuser = false;
                if (await FirebaseHelper.CheckEmail(user.Email) == false)
                {
                    await FirebaseHelper.AddUser(user.Email, user.Picture, user.Name, user.Id, user.IsToggled, user.IsLoggedIn);

                    newuser = true;
                }


                ClearPersisitance();

                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.Properties.Add("IsToggled", false);
                await Application.Current.SavePropertiesAsync();                 //persistance

                if (newuser)
                {
                    await FirebaseHelper.AddPantryItem("Example Item", "5", "12/15");
                }



                App.Current.MainPage = new AppShell();
            }
        }
        public async void HandleDelete(ShoppingListItems items)
        {
            await FirebaseHelper.DeleteShoppingList(items.ItemName);

            await RefreshList();
        }
 private async Task <List <ShoppingListItems> > GetShoppingItems()
 {
     return(await FirebaseHelper.GetShoppingList());
 }
Beispiel #8
0
        public async void HandleDelete(PantryItems pantryItem)
        {
            await FirebaseHelper.DeletePantryItem(pantryItem.ItemName);

            await RefreshPantry();
        }
Beispiel #9
0
 private async Task <List <PantryItems> > GetPantryItems()
 {
     return(await FirebaseHelper.GetPantry());
 }
Beispiel #10
0
        private async void HandleDelete(RecipeItems recipe)
        {
            await FirebaseHelper.DeleteRecipe(recipe.RecipeName);

            await RefreshRecipes();
        }
Beispiel #11
0
 private async Task <List <RecipeItems> > GetRecipeItems()
 {
     return(await FirebaseHelper.GetRecipes());
 }