https and auth token rollover
This commit is contained in:
@@ -13,7 +13,7 @@ using UnityEngine.UI;
|
||||
|
||||
public class LoginManager : MonoBehaviour
|
||||
{
|
||||
public const string AuthBaseUrl = "http://vps.playpoolstudios.com:2612";
|
||||
public const string AuthBaseUrl = "https://kickkingsapi.playpoolstudios.com";
|
||||
const string PlayerPrefsAuthKey = "WalkInvest.AuthToken";
|
||||
|
||||
const int MIN_USERNAME_LENGTH = 3;
|
||||
@@ -93,6 +93,9 @@ public class LoginManager : MonoBehaviour
|
||||
}
|
||||
instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
if (string.IsNullOrEmpty(AuthToken))
|
||||
ClearLocalUserProfile();
|
||||
}
|
||||
|
||||
void Start()
|
||||
@@ -143,11 +146,43 @@ public class LoginManager : MonoBehaviour
|
||||
|
||||
IEnumerator ResumeSessionCoroutine()
|
||||
{
|
||||
yield return StartCoroutine(FetchUserDataCoroutine(null, true));
|
||||
ProceedToMainMenu();
|
||||
ClearLocalUserProfile();
|
||||
bool ok = false;
|
||||
string errMsg = null;
|
||||
yield return StartCoroutine(FetchUserDataCoroutine((success, err, _) =>
|
||||
{
|
||||
ok = success;
|
||||
errMsg = err;
|
||||
}, true));
|
||||
|
||||
if (ok)
|
||||
ProceedToMainMenu();
|
||||
else
|
||||
{
|
||||
InvalidateStoredSession();
|
||||
if (error_txt != null)
|
||||
error_txt.text = string.IsNullOrEmpty(errMsg) ? "Session expired. Please sign in again." : errMsg;
|
||||
}
|
||||
|
||||
SetBusy(false);
|
||||
}
|
||||
|
||||
/// <summary>Clears cached profile only (token unchanged). Call when leaving a broken state without wiping prefs.</summary>
|
||||
static void ClearLocalUserProfile()
|
||||
{
|
||||
_currentUser = null;
|
||||
}
|
||||
|
||||
/// <summary>Removes auth token from memory and disk and clears cached profile (login screen recovery).</summary>
|
||||
static void InvalidateStoredSession()
|
||||
{
|
||||
AuthToken = "";
|
||||
ClearLocalUserProfile();
|
||||
ClearMatchYourTeam();
|
||||
PlayerPrefs.DeleteKey(PlayerPrefsAuthKey);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
static void ProceedToMainMenu()
|
||||
{
|
||||
if (LevelLoadManager.instance != null)
|
||||
@@ -230,6 +265,7 @@ public class LoginManager : MonoBehaviour
|
||||
{
|
||||
SetBusy(true);
|
||||
error_txt.text = "";
|
||||
ClearLocalUserProfile();
|
||||
|
||||
using (var request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST))
|
||||
{
|
||||
@@ -265,8 +301,20 @@ public class LoginManager : MonoBehaviour
|
||||
PlayerPrefs.SetString(PlayerPrefsAuthKey, resp.token);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
yield return StartCoroutine(FetchUserDataCoroutine(null, true));
|
||||
ProceedToMainMenu();
|
||||
bool profileOk = false;
|
||||
string profileErr = null;
|
||||
yield return StartCoroutine(FetchUserDataCoroutine((success, err, _) =>
|
||||
{
|
||||
profileOk = success;
|
||||
profileErr = err;
|
||||
}, true));
|
||||
|
||||
if (profileOk)
|
||||
ProceedToMainMenu();
|
||||
else if (error_txt != null)
|
||||
error_txt.text = string.IsNullOrEmpty(profileErr)
|
||||
? "Signed in but could not load your profile. Check your connection and try again."
|
||||
: profileErr;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -52,9 +52,17 @@ public class MainMenuManager : MonoBehaviour
|
||||
ccText.text = "";
|
||||
rcText.text = "";
|
||||
LoginManager.instance.GetUserData((success, error, user) => {
|
||||
if(success){
|
||||
if (success)
|
||||
{
|
||||
OnUserUpdated(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (btnPlay != null)
|
||||
btnPlay.interactable = false;
|
||||
if (rcPlayText != null)
|
||||
rcPlayText.text = string.IsNullOrEmpty(error) ? "Could not load profile. Try again." : error;
|
||||
}
|
||||
});
|
||||
|
||||
btnBuyUsd5.onClick.AddListener(() => OnBuy(RcPack.Usd5));
|
||||
@@ -75,11 +83,23 @@ public class MainMenuManager : MonoBehaviour
|
||||
btnPlay.onClick.AddListener(OnPlay);
|
||||
}
|
||||
|
||||
void OnPlay(){
|
||||
if(LoginManager.CurrentUser.rc < 21){
|
||||
void OnPlay()
|
||||
{
|
||||
if (LoginManager.CurrentUser == null)
|
||||
{
|
||||
Debug.LogError("Play blocked: user profile not loaded.");
|
||||
return;
|
||||
}
|
||||
if (LoginManager.CurrentUser.rc < 21)
|
||||
{
|
||||
Debug.LogError("Not enough RC to play");
|
||||
return;
|
||||
}
|
||||
if (CupidLobby.instance == null)
|
||||
{
|
||||
Debug.LogError("Play blocked: CupidLobby is missing from this scene.");
|
||||
return;
|
||||
}
|
||||
CupidLobby.instance.Matchmake();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user