Skip to content
Permalink
Browse files

Replaced some simple UAD.instance.token checks with IsTokenValid

  • Loading branch information...
Jackson Wood
Jackson Wood committed Jul 1, 2019
1 parent 701ec24 commit 96f3dfc2e60e4e225c9bcbcd36de5933b4bd0a46
@@ -71,7 +71,7 @@ protected virtual void OnEnable()
{
this.profile = null;

if(!UserAuthenticationData.instance.Equals(UserAuthenticationData.NONE))
if(UserAuthenticationData.instance.IsTokenValid)
{
this.isModListLoading = true;
this.modOptions = new string[]{ "Loading..." };
@@ -44,7 +44,7 @@ protected virtual void OnEnable()
uploadSucceededMessage = null;
uploadFailedMessage = null;

if(!UserAuthenticationData.instance.Equals(UserAuthenticationData.NONE))
if(UserAuthenticationData.instance.IsTokenValid)
{
ModManager.GetAuthenticatedUserProfile((userProfile) =>
{
@@ -93,13 +93,22 @@ public static bool AssertAuthorizationDetails(bool isUserTokenRequired)
return false;
}

if(isUserTokenRequired
&& String.IsNullOrEmpty(UserAuthenticationData.instance.token))
if(isUserTokenRequired)
{
Debug.LogError("[mod.io] API request to modification or User-specific"
+ " endpoints cannot be made without first setting the"
+ " User Authorization Data instance with a valid token.");
return false;
if(String.IsNullOrEmpty(UserAuthenticationData.instance.token))
{
Debug.LogError("[mod.io] API request to modification or User-specific"
+ " endpoints cannot be made without first setting the"
+ " User Authorization Data instance with a valid token.");
return false;
}
else if(UserAuthenticationData.instance.wasTokenRejected)
{
Debug.LogWarning("[mod.io] An API request is being made with a UserAuthenticationData"
+ " token that has been flagged as previously rejected."
+ " A check on UserAuthenticationData.instance.IsTokenValid"
+ " should be made prior to making user-authrization calls.");
}
}

return true;
@@ -1755,7 +1755,7 @@ public static System.Collections.IEnumerator DownloadAndUpdateMods_Coroutine(ILi
onSuccess,
onError);
}
else if(!string.IsNullOrEmpty(UserAuthenticationData.instance.token))
else if(UserAuthenticationData.instance.IsTokenValid)
{
APIClient.GetAuthenticatedUser(
(p) =>
@@ -243,11 +243,7 @@ private System.Collections.IEnumerator StartFetchRemoteData()

this.StartCoroutine(FetchGameProfile());

if(UserAuthenticationData.instance.Equals(UserAuthenticationData.NONE))
{
yield return this.StartCoroutine(UpdateAllSubscribedModProfiles());
}
else
if(UserAuthenticationData.instance.IsTokenValid)
{
yield return this.StartCoroutine(FetchUserProfile());

@@ -257,6 +253,10 @@ private System.Collections.IEnumerator StartFetchRemoteData()
yield return this.StartCoroutine(SynchronizeSubscriptionsWithServer());
}
}
else
{
yield return this.StartCoroutine(UpdateAllSubscribedModProfiles());
}

this.StartCoroutine(VerifySubscriptionInstallations());
this.StartCoroutine(PollForSubscribedModEventsCoroutine());
@@ -300,7 +300,14 @@ private System.Collections.IEnumerator FetchGameProfile()
int reattemptDelay = CalculateReattemptDelay(requestError);
if(requestError.isAuthenticationInvalid)
{
if(String.IsNullOrEmpty(UserAuthenticationData.instance.token))
if(UserAuthenticationData.instance.IsTokenValid)
{
MessageSystem.QueueMessage(MessageDisplayData.Type.Error,
requestError.displayMessage);

UserAccountManagement.MarkAuthTokenRejected();
}
else
{
Debug.LogWarning("[mod.io] Unable to retrieve the game profile from the mod.io"
+ " servers. Please check you Game Id and APIKey in the"
@@ -310,13 +317,6 @@ private System.Collections.IEnumerator FetchGameProfile()
"Failed to collect game data from mod.io.\n"
+ requestError.displayMessage);
}
else
{
MessageSystem.QueueMessage(MessageDisplayData.Type.Error,
requestError.displayMessage);

UserAccountManagement.MarkAuthTokenRejected();
}

yield break;
}
@@ -349,7 +349,7 @@ private System.Collections.IEnumerator FetchGameProfile()

private System.Collections.IEnumerator FetchUserProfile()
{
Debug.Assert(!String.IsNullOrEmpty(UserAuthenticationData.instance.token));
Debug.Assert(UserAuthenticationData.instance.IsTokenValid);

bool succeeded = false;
string fetchToken = UserAuthenticationData.instance.token;
@@ -438,7 +438,7 @@ private System.Collections.IEnumerator FetchUserProfile()
private System.Collections.IEnumerator PushQueuedSubscribes(Action<List<ModProfile>> onCompleted)
{
// early out if not authenticated or no queued subs
if(string.IsNullOrEmpty(UserAuthenticationData.instance.token)
if(!UserAuthenticationData.instance.IsTokenValid
|| this.m_queuedSubscribes.Count == 0)
{
if(onCompleted != null) { onCompleted(new List<ModProfile>()); }
@@ -560,7 +560,7 @@ private System.Collections.IEnumerator PushQueuedSubscribes(Action<List<ModProfi
private System.Collections.IEnumerator PushQueuedUnsubscribes(Action<List<int>> onCompleted)
{
// early out if not authenticated or no queued actions
if(string.IsNullOrEmpty(UserAuthenticationData.instance.token)
if(!UserAuthenticationData.instance.IsTokenValid
|| this.m_queuedUnsubscribes.Count == 0)
{
if(onCompleted != null) { onCompleted(new List<int>(0)); }
@@ -640,8 +640,8 @@ private System.Collections.IEnumerator PushQueuedUnsubscribes(Action<List<int>>
Action onCompleted,
Action<WebRequestError> onFailed)
{
// early out if not authenticated or no queued actions
if(string.IsNullOrEmpty(UserAuthenticationData.instance.token))
// early out if not authenticated
if(!UserAuthenticationData.instance.IsTokenValid)
{
if(onCompleted != null) { onCompleted(); }
yield break;

0 comments on commit 96f3dfc

Please sign in to comment.
You can’t perform that action at this time.