Example #1
0
 public Person(GoogleUserProfile gprofile = null, FacebookUserProfile fprofile = null)
 {
     Name             = gprofile.Name;
     Email            = gprofile.Email;
     AuthenticationId = gprofile.Id;
     ProfileImageUrl  = gprofile.Picture;
     Initialize();
 }
        /// <summary>
        /// Registers an athlete with the backend and returns the new athlete profile
        /// </summary>
        async Task <Person> RegisterPerson(GoogleUserProfile profile)
        {
            AuthenticationStatus = "Registering person";
            var athlete = new Person(profile);

            await AzureService.Instance.PersonManager.UpsertAsync(athlete);

            //"You're now an officially registered athlete!".ToToast();
            Debug.WriteLine("You're now an officially registered GAMr!");
            Settings.RegistrationComplete = true;
            return(athlete);
        }
        public void LogOut(bool clearCookies)
        {
            //Utility.SetSecured("AuthToken", string.Empty, "xamarin.sport", "authentication");
            //AzureService.Instance.Client.Logout();

            AuthUserProfile            = null;
            Settings.GoogleAccessToken = null;
            Settings.GamrID            = null;
            Settings.GoogleUserId      = null;

            if (clearCookies)
            {
                Settings.RegistrationComplete = false;
                _authenticator.ClearCookies();
            }
        }
Example #4
0
        public SetAliasPage(GoogleUserProfile Profile)
        {
            InitializeComponent();
            PersonProfile = new nerdytinder.Person()
            {
                Name            = Profile.Name,
                Email           = Profile.Email,
                ProfileImageUrl = Profile.Picture
            };

            labelName.Text  = PersonProfile.Name;
            labelEmail.Text = PersonProfile.Email;
            labelUrl.Source = PersonProfile.ProfileImageUrl;
            state.Items.Add("CA");
            state.Items.Add("TX");
            state.Items.Add("NY");
        }
        /// <summary>
        /// Attempts to get the user profile from Google. Will use the refresh token if the auth token has expired
        /// </summary>
        async public Task <bool> GetUserProfile()
        {
            //Can't get profile w/out a token
            if (Settings.GoogleAccessToken == null)
            {
                return(false);
            }

            if (AuthUserProfile != null)
            {
                return(true);
            }

            AuthenticationStatus = "Getting Google user profile";
            System.Diagnostics.Debug.WriteLine("Exception=B");
            var task = GoogleApiService.Instance.GetUserProfile();

            System.Diagnostics.Debug.WriteLine("Exception=A");
            await RunSafe(task, false);

            /*
             * try
             * {
             *  await Task.Run(() =>
             *  {
             *      task.Start();
             *      task.Wait();
             *  });
             * }
             * catch (Exception e)
             * {
             *  System.Diagnostics.Debug.WriteLine("Exception=" + e.GetBaseException());
             * }
             */
            System.Diagnostics.Debug.WriteLine("Exception=AR");

            if (task.IsFaulted && task.IsCompleted)
            {
                //return false;
                //Need to get refresh token from Azure somehow
                //Likely our authtoken has expired
                AuthenticationStatus = "Refreshing token";
                MobileServiceUser user = await AzureService.Instance.Client.RefreshUserAsync();

                var identity = await AzureService.Instance.Client.InvokeApiAsync("getUserIdentity", null, HttpMethod.Get, null);

                Settings.GoogleAccessToken = identity.Value <string>("token");
                Settings.AzureUserID       = user.UserId;
                Settings.AzureAuthToken    = user.MobileServiceAuthenticationToken;
                return(await GetUserProfile());

                //var refreshTask = GoogleApiService.Instance.GetNewAuthToken(Settings.Instance.RefreshToken);
                //await Task.Run(() => {
                //    refreshTask.Start();
                //    refreshTask.Wait();
                //});
                //await RunSafe(refreshTask);

                //if(refreshTask.IsCompleted && !refreshTask.IsFaulted)
                //{
                //Success in getting a new auth token - now lets attempt to get the profile again
                //if(!string.IsNullOrWhiteSpace(refreshTask.Result) && App.AuthToken != refreshTask.Result)
                //{
                //We have a valid token now, let's try this again
                //		App.AuthToken = refreshTask.Result;
                //		await Settings.Instance.Save();
                //		return await GetUserProfile();
                //	}
                //}
            }


            if (task.IsCompleted && !task.IsFaulted && task.Result != null)
            {
                AuthenticationStatus = "Authentication complete";
                AuthUserProfile      = task.Result;

                //InsightsManager.Identify(AuthUserProfile.Email, new Dictionary<string, string> {
                //	{
                //		"Name",
                //		AuthUserProfile.Name
                //	}
                //});

                Settings.GoogleUserId = AuthUserProfile.Id;
            }
            else
            {
                AuthenticationStatus = "Unable to authenticate";
            }

            return(AuthUserProfile != null);
        }