Ejemplo n.º 1
0
		/// <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(App.AuthToken == null)
				return false;

			using(new Busy(this))
			{
				AuthenticationStatus = "Getting Google user profile";
				var task = GoogleApiService.Instance.GetUserProfile();
				await RunSafe(task, false);

				if(task.IsFaulted && task.IsCompleted)
				{
					//Likely our authtoken has expired
//					AuthenticationStatus = "Refreshing token";
//
//					var refreshTask = GoogleApiService.Instance.GetNewAuthToken(Settings.Instance.RefreshToken);
//					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) && Settings.Instance.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;

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

					Settings.Instance.AuthUserID = AuthUserProfile.Id;
					await Settings.Instance.Save();
				}
				else
				{
					AuthenticationStatus = "Unable to authenticate";
					_doResetWebCache = true;
				}
			}

			return AuthUserProfile != null;
		}
Ejemplo n.º 2
0
		public void LogOut()
		{
			_doResetWebCache = true;

			Settings.Instance.AthleteId = null;
			Settings.Instance.AuthUserID = null;
			App.AuthToken = null;
			Settings.Instance.RegistrationComplete = false;
			Settings.Instance.Save();
			AuthUserProfile = null;
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Registers an athlete with the backend and returns the new athlete profile
		/// </summary>
		async Task<Athlete> RegisterAthlete(UserProfile profile)
		{
			AuthenticationStatus = "Registering athlete";
			var athlete = new Athlete(profile);

			var task = AzureService.Instance.SaveAthlete(athlete);
			await RunSafe(task);

			if(task.IsCompleted && task.IsFaulted)
				return null;

			"You're now an officially registered athlete!".ToToast();
			return athlete;
		}