Ejemplo n.º 1
0
        public async void OnAppleSignInRequest()
        {
            var account = await appleSignInService.SignInAsync();

            if (account != null)
            {
                Preferences.Set(App.LoggedInKey, true);
                await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId);

                // System.Diagnostics.Debug.WriteLine($"Signed in!\n  Name: {account?.Name ?? string.Empty}\n  Email: {account?.Email ?? string.Empty}\n  UserId: {account?.UserId ?? string.Empty}");

                var client          = new HttpClient();
                var socialLogInPost = new SocialLogInPost();

                if (apple_token == null && apple_email == null)
                {
                    apple_token = account.Token.Substring(0, 500);
                    apple_email = account.Email;
                    AppleUserProfileAsync(apple_token, apple_email, account.Name);
                }

                if (!apple_token.Equals(account.Token) && apple_token != null)
                {
                    DateTime today          = DateTime.Now;
                    DateTime expirationDate = today.AddDays(Constant.days);
                    Application.Current.Properties["time_stamp"] = expirationDate;

                    apple_token = account.Token.Substring(0, 500);

                    UpdateTokensPost updateTokens = new UpdateTokensPost();
                    updateTokens.access_token     = apple_token;
                    updateTokens.refresh_token    = apple_token;
                    updateTokens.uid              = (string)Application.Current.Properties["uid"];
                    updateTokens.social_timestamp = expirationDate.ToString("yyyy-MM-dd HH:mm:ss");

                    var updatePostSerilizedObject = JsonConvert.SerializeObject(updateTokens);
                    var updatePostContent         = new StringContent(updatePostSerilizedObject, Encoding.UTF8, "application/json");
                    var RDSrespose = await client.PostAsync(Constant.UpdateTokensUrl, updatePostContent);

                    if (RDSrespose.IsSuccessStatusCode)
                    {
                        AppleUserProfileAsync(apple_token, apple_email, string.Empty);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("We were not able to update your APPLE token");
                    }
                }
            }
            else
            {
                AppleError?.Invoke(this, default(EventArgs));
            }
        }
Ejemplo n.º 2
0
        public async void OnAppleSignInRequest()
        {
            var account = await appleSignInService.SignInAsync();

            if (account != null)
            {
                Preferences.Set(App.LoggedInKey, true);
                await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId);

                if (account.Token == null)
                {
                    account.Token = "";
                }
                if (account.Email != null)
                {
                    if (Application.Current.Properties.ContainsKey(account.UserId.ToString()))
                    {
                        Application.Current.Properties[account.UserId.ToString()] = account.Email;
                    }
                    else
                    {
                        Application.Current.Properties[account.UserId.ToString()] = account.Email;
                    }
                }
                if (account.Email == null)
                {
                    account.Email = "";
                }
                if (account.Name == null)
                {
                    account.Name = "";
                }

                System.Diagnostics.Debug.WriteLine((string)Application.Current.Properties[account.UserId.ToString()]);
                AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name);
            }
            else
            {
                AppleError?.Invoke(this, default(EventArgs));
            }
        }
Ejemplo n.º 3
0
        public async void OnAppleSignInRequest()
        {
            try
            {
                var account = await appleSignInService.SignInAsync();

                if (account != null)
                {
                    Preferences.Set(App.LoggedInKey, true);
                    await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId);

                    if (account.Token == null)
                    {
                        account.Token = "";
                    }
                    if (account.Email != null)
                    {
                        if (Application.Current.Properties.ContainsKey(account.UserId.ToString()))
                        {
                            //Application.Current.Properties[account.UserId.ToString()] = account.Email;
                            Debug.WriteLine((string)Application.Current.Properties[account.UserId.ToString()]);
                        }
                        else
                        {
                            Application.Current.Properties[account.UserId.ToString()] = account.Email;
                        }
                    }
                    if (account.Email == null)
                    {
                        account.Email = "";
                    }
                    if (account.Name == null)
                    {
                        account.Name = "";
                    }

                    if (Application.Current.Properties.ContainsKey(account.UserId.ToString()))
                    {
                        account.Email = (string)Application.Current.Properties[account.UserId.ToString()];
                        //Application.Current.MainPage = new DeliveriesPage("","",null,account,"APPLE");
                        //AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name);
                    }
                    else
                    {
                        var client        = new HttpClient();
                        var getAppleEmail = new AppleEmail();
                        getAppleEmail.social_id = account.UserId;

                        var socialLogInPostSerialized = JsonConvert.SerializeObject(getAppleEmail);

                        System.Diagnostics.Debug.WriteLine(socialLogInPostSerialized);

                        var postContent = new StringContent(socialLogInPostSerialized, Encoding.UTF8, "application/json");
                        var RDSResponse = await client.PostAsync("https://tsx3rnuidi.execute-api.us-west-1.amazonaws.com/dev/api/v2/AppleEmail", postContent);

                        var responseContent = await RDSResponse.Content.ReadAsStringAsync();

                        System.Diagnostics.Debug.WriteLine(responseContent);
                        if (RDSResponse.IsSuccessStatusCode)
                        {
                            var data = JsonConvert.DeserializeObject <AppleUser>(responseContent);
                            Application.Current.Properties[account.UserId.ToString()] = data.result[0].customer_email;
                            account.Email = (string)Application.Current.Properties[account.UserId.ToString()];
                            //Application.Current.MainPage = new DeliveriesPage("", "", null, account, "APPLE");
                            //AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name);
                        }
                        else
                        {
                            await Application.Current.MainPage.DisplayAlert("Ooops", "Our system is not working. We can't process your request at this moment", "OK");
                        }
                    }
                }
                else
                {
                    AppleError?.Invoke(this, default(EventArgs));
                }
            }
            catch (Exception apple)
            {
                await Application.Current.MainPage.DisplayAlert("Error", apple.Message, "OK");
            }
        }
Ejemplo n.º 4
0
        public async void OnAppleSignInRequest()
        {
            Console.WriteLine("in LoginViewModel, entered OnAppleSignInRequest");
            //================================
            //CARLOS UPDATE APPLE SOLUTION
            try
            {
                var account = await appleSignInService.SignInAsync();

                if (account != null)
                {
                    Debug.WriteLine("reached inside account");
                    Preferences.Set(App.LoggedInKey, true);
                    await SecureStorage.SetAsync(App.AppleUserIdKey, account.UserId);

                    if (account.Token == null)
                    {
                        account.Token = "";
                    }
                    if (account.Email != null)
                    {
                        Debug.WriteLine("email not null: " + account.Email);
                        if (Application.Current.Properties.ContainsKey(account.UserId.ToString()))
                        {
                            //Application.Current.Properties[account.UserId.ToString()] = account.Email;
                            Debug.WriteLine((string)Application.Current.Properties[account.UserId.ToString()]);
                        }
                        else
                        {
                            Application.Current.Properties[account.UserId.ToString()] = account.Email;
                        }
                    }
                    if (account.Email == null)
                    {
                        account.Email = "";
                    }
                    if (account.Name == null)
                    {
                        account.Name = "";
                    }

                    if (Application.Current.Properties.ContainsKey(account.UserId.ToString()))
                    {
                        AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name);
                    }
                    else
                    {
                        var client        = new HttpClient();
                        var getAppleEmail = new AppleEmail();
                        getAppleEmail.social_id = account.UserId;

                        var socialLogInPostSerialized = JsonConvert.SerializeObject(getAppleEmail);

                        Debug.WriteLine(socialLogInPostSerialized);
                        Debug.WriteLine("email:" + account.Email);
                        Debug.WriteLine("userid:" + account.UserId);
                        var postContent = new StringContent(socialLogInPostSerialized, Encoding.UTF8, "application/json");
                        var RDSResponse = await client.PostAsync(Constant.AppleEmailUrl, postContent);

                        var responseContent = await RDSResponse.Content.ReadAsStringAsync();

                        Debug.WriteLine(responseContent);
                        if (RDSResponse.IsSuccessStatusCode)
                        {
                            var data = JsonConvert.DeserializeObject <AppleUser>(responseContent);
                            Debug.WriteLine("data:" + data);
                            Debug.WriteLine("data:" + data.ToString());
                            Application.Current.Properties[account.UserId.ToString()] = data.result[0].customer_email;
                            //Application.Current.Properties[account.UserId.ToString()] = "*****@*****.**";
                            AppleUserProfileAsync(account.UserId, account.Token, (string)Application.Current.Properties[account.UserId.ToString()], account.Name);
                        }
                        else
                        {
                            await Application.Current.MainPage.DisplayAlert("Ooops", "Our system is not working. We can't process your request at this moment", "OK");
                        }
                    }
                }
                else
                {
                    AppleError?.Invoke(this, default(EventArgs));
                }
            }
            catch (Exception apple)
            {
                await Application.Current.MainPage.DisplayAlert("Error", apple.Message, "OK");
            }
            //================================
        }