<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using HaloLive.Models.Authentication;
using HaloLive.Network;
using SceneJect.Common;
using UnityEngine;
using Unitysync.Async;

namespace GaiaOnline
{
	[Injectee]
	public sealed class AuthenticationClient : MonoBehaviour
	{
		/// <summary>
		/// Authentication service.
		/// </summary>
		[Inject]
		private IAuthenticationService AuthService { get; }

		[Inject]
		private IUserAuthenticationDetailsContainer AuthDetails { get; }

		//TODO: Validate services and auth details
		public void AuthenticateUser()
		{
			//TODO: Add the ILogger service
			Debug.Log($"Connecting with User: {AuthDetails.UserName}");

			//Async auth request that dispatches to OnAuthResponseRecieved
			AuthService.TryAuthenticate(new AuthenticationRequestModel(AuthDetails.UserName, AuthDetails.Password))
				.UnityAsyncContinueWith(this, OnAuthResponseRecieved);
		}

		private void OnAuthResponseRecieved(JWTModel result)
		{
			Debug.Log($"Recieved Auth Response Result: {result.isTokenValid}");

			if(result == null) throw new ArgumentNullException(nameof(result));

			if(!result.isTokenValid)
				throw new NotImplementedException("TODO: Handle failed authentication.");

			Debug.Log($"Setting player prefs access token");

			//TODO: maybe extract this into seperate interface
			//the result should be valid and we should store the result in the player prefs
			PlayerPrefs.SetString(PlayerPreferences.UserToken.ToString(), result.AccessToken);
		}
	}
}<commit_msg>Added OnSuccess event for auth client<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using HaloLive.Models.Authentication;
using HaloLive.Network;
using SceneJect.Common;
using UnityEngine;
using UnityEngine.Events;
using Unitysync.Async;

namespace GaiaOnline
{
	[Injectee]
	public sealed class AuthenticationClient : MonoBehaviour
	{
		/// <summary>
		/// Authentication service.
		/// </summary>
		[Inject]
		private IAuthenticationService AuthService { get; }

		[Inject]
		private IUserAuthenticationDetailsContainer AuthDetails { get; }

		[SerializeField]
		private UnityEvent OnRecievedSuccessfulAuthResponse;

		//TODO: Validate services and auth details
		public void AuthenticateUser()
		{
			//TODO: Add the ILogger service
			Debug.Log($"Connecting with User: {AuthDetails.UserName}");

			//Async auth request that dispatches to OnAuthResponseRecieved
			AuthService.TryAuthenticate(new AuthenticationRequestModel(AuthDetails.UserName, AuthDetails.Password))
				.UnityAsyncContinueWith(this, OnAuthResponseRecieved);
		}

		private void OnAuthResponseRecieved(JWTModel result)
		{
			Debug.Log($"Recieved Auth Response Result: {result.isTokenValid}");

			if(result == null) throw new ArgumentNullException(nameof(result));

			if(!result.isTokenValid)
				throw new NotImplementedException("TODO: Handle failed authentication.");

			Debug.Log($"Setting player prefs access token");

			//TODO: maybe extract this into seperate interface
			//the result should be valid and we should store the result in the player prefs
			PlayerPrefs.SetString(PlayerPreferences.UserToken.ToString(), result.AccessToken);

			OnRecievedSuccessfulAuthResponse?.Invoke();
		}
	}
}
{'fraction_non_alphanumeric': 0.09247878255779923, 'fraction_numerical': 0.0, 'mean_word_length': 5.03886925795053, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6000286', 'n_tokens_mistral': 1067, 'n_tokens_neox': 954, 'n_words': 260}