rc
This commit is contained in:
@@ -21,6 +21,7 @@ public class LoginManager : MonoBehaviour
|
||||
const int MAX_USERNAME_LENGTH = 16;
|
||||
const int MIN_PASSWORD_LENGTH = 8;
|
||||
const int MAX_PASSWORD_LENGTH = 20;
|
||||
const int ShortAuthMessageMaxLength = 36;
|
||||
|
||||
[Header("Login")]
|
||||
[SerializeField] private TMP_InputField usernameInputLogin;
|
||||
@@ -33,9 +34,6 @@ public class LoginManager : MonoBehaviour
|
||||
[SerializeField] private TMP_InputField passwordInputRegister;
|
||||
[SerializeField] private Button btnRegister;
|
||||
|
||||
[Header("UI")]
|
||||
[SerializeField] private TMP_Text error_txt;
|
||||
|
||||
[Header("Server messages (GET /table_settings, no auth)")]
|
||||
[Header("Update")]
|
||||
[SerializeField] private GameObject serverUpdatePanel;
|
||||
@@ -60,6 +58,7 @@ public class LoginManager : MonoBehaviour
|
||||
bool _appPaused;
|
||||
bool _appFocused = true;
|
||||
bool _handlingKeepaliveUnauthorized;
|
||||
string _pendingAuthMessage;
|
||||
|
||||
public static string AuthToken { get; private set; }
|
||||
|
||||
@@ -110,7 +109,6 @@ public class LoginManager : MonoBehaviour
|
||||
|
||||
void Awake()
|
||||
{
|
||||
error_txt.text = "";
|
||||
HideServerMessagePanels();
|
||||
AuthToken = PlayerPrefs.GetString(PlayerPrefsAuthKey, "");
|
||||
|
||||
@@ -120,6 +118,7 @@ public class LoginManager : MonoBehaviour
|
||||
}
|
||||
instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
|
||||
if (string.IsNullOrEmpty(AuthToken))
|
||||
ClearLocalUserProfile();
|
||||
@@ -217,8 +216,7 @@ public class LoginManager : MonoBehaviour
|
||||
else
|
||||
{
|
||||
InvalidateStoredSession();
|
||||
if (error_txt != null)
|
||||
error_txt.text = string.IsNullOrEmpty(errMsg) ? "Session expired. Please sign in again." : errMsg;
|
||||
ShowAuthMessage(string.IsNullOrEmpty(errMsg) ? "Session expired. Please sign in again." : errMsg);
|
||||
}
|
||||
|
||||
SetBusy(false);
|
||||
@@ -269,6 +267,40 @@ public class LoginManager : MonoBehaviour
|
||||
if (btnRegister != null) btnRegister.interactable = !busy;
|
||||
}
|
||||
|
||||
void ShowAuthMessage(string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
if (MessageBoxDialog.instance == null)
|
||||
{
|
||||
_pendingAuthMessage = message;
|
||||
return;
|
||||
}
|
||||
|
||||
_pendingAuthMessage = null;
|
||||
if (message.Length <= ShortAuthMessageMaxLength)
|
||||
MessageBoxDialog.instance.ShowMessageBox(message);
|
||||
else
|
||||
MessageBoxDialog.instance.ShowMessageBox("Error", message);
|
||||
}
|
||||
|
||||
void HideAuthMessage()
|
||||
{
|
||||
if (MessageBoxDialog.instance != null)
|
||||
MessageBoxDialog.instance.HideMessageBox();
|
||||
}
|
||||
|
||||
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_pendingAuthMessage) || MessageBoxDialog.instance == null)
|
||||
return;
|
||||
|
||||
string message = _pendingAuthMessage;
|
||||
_pendingAuthMessage = null;
|
||||
ShowAuthMessage(message);
|
||||
}
|
||||
|
||||
void OnLogin()
|
||||
{
|
||||
if (_authInProgress) return;
|
||||
@@ -278,19 +310,19 @@ public class LoginManager : MonoBehaviour
|
||||
string password = passwordInputLogin.text;
|
||||
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
error_txt.text = "Please fill in all fields";
|
||||
ShowAuthMessage("Please fill in all fields");
|
||||
return;
|
||||
}
|
||||
|
||||
if (username.Length < MIN_USERNAME_LENGTH || username.Length > MAX_USERNAME_LENGTH)
|
||||
{
|
||||
error_txt.text = "Username must be between " + MIN_USERNAME_LENGTH + " and " + MAX_USERNAME_LENGTH + " characters";
|
||||
ShowAuthMessage("Username must be between " + MIN_USERNAME_LENGTH + " and " + MAX_USERNAME_LENGTH + " characters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.Length < MIN_PASSWORD_LENGTH || password.Length > MAX_PASSWORD_LENGTH)
|
||||
{
|
||||
error_txt.text = "Password must be between " + MIN_PASSWORD_LENGTH + " and " + MAX_PASSWORD_LENGTH + " characters";
|
||||
ShowAuthMessage("Password must be between " + MIN_PASSWORD_LENGTH + " and " + MAX_PASSWORD_LENGTH + " characters");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -308,26 +340,26 @@ public class LoginManager : MonoBehaviour
|
||||
string password = passwordInputRegister.text;
|
||||
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
error_txt.text = "Please fill in all fields";
|
||||
ShowAuthMessage("Please fill in all fields");
|
||||
return;
|
||||
}
|
||||
|
||||
email = email.Trim().ToLowerInvariant();
|
||||
if (!IsValidEmailFormat(email))
|
||||
{
|
||||
error_txt.text = "Please enter a valid email address";
|
||||
ShowAuthMessage("Please enter a valid email address");
|
||||
return;
|
||||
}
|
||||
|
||||
if (username.Length < MIN_USERNAME_LENGTH || username.Length > MAX_USERNAME_LENGTH)
|
||||
{
|
||||
error_txt.text = "Username must be between " + MIN_USERNAME_LENGTH + " and " + MAX_USERNAME_LENGTH + " characters";
|
||||
ShowAuthMessage("Username must be between " + MIN_USERNAME_LENGTH + " and " + MAX_USERNAME_LENGTH + " characters");
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.Length < MIN_PASSWORD_LENGTH || password.Length > MAX_PASSWORD_LENGTH)
|
||||
{
|
||||
error_txt.text = "Password must be between " + MIN_PASSWORD_LENGTH + " and " + MAX_PASSWORD_LENGTH + " characters";
|
||||
ShowAuthMessage("Password must be between " + MIN_PASSWORD_LENGTH + " and " + MAX_PASSWORD_LENGTH + " characters");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -370,7 +402,7 @@ public class LoginManager : MonoBehaviour
|
||||
IEnumerator AuthPostCoroutine(string url, string jsonBody, string successMessage)
|
||||
{
|
||||
SetBusy(true);
|
||||
error_txt.text = "";
|
||||
HideAuthMessage();
|
||||
ClearLocalUserProfile();
|
||||
|
||||
using (var request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST))
|
||||
@@ -387,14 +419,14 @@ public class LoginManager : MonoBehaviour
|
||||
if (request.result != UnityWebRequest.Result.Success &&
|
||||
request.result != UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
error_txt.text = string.IsNullOrEmpty(request.error) ? "Network error" : request.error;
|
||||
ShowAuthMessage(string.IsNullOrEmpty(request.error) ? "Network error" : request.error);
|
||||
SetBusy(false);
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
error_txt.text = "Empty response from server";
|
||||
ShowAuthMessage("Empty response from server");
|
||||
SetBusy(false);
|
||||
yield break;
|
||||
}
|
||||
@@ -418,14 +450,14 @@ public class LoginManager : MonoBehaviour
|
||||
|
||||
if (profileOk)
|
||||
ProceedToMainMenu();
|
||||
else if (error_txt != null)
|
||||
error_txt.text = string.IsNullOrEmpty(profileErr)
|
||||
else
|
||||
ShowAuthMessage(string.IsNullOrEmpty(profileErr)
|
||||
? "Signed in but could not load your profile. Check your connection and try again."
|
||||
: profileErr;
|
||||
: profileErr);
|
||||
}
|
||||
else
|
||||
{
|
||||
error_txt.text = string.IsNullOrEmpty(resp.error) ? "Request failed" : resp.error;
|
||||
ShowAuthMessage(string.IsNullOrEmpty(resp.error) ? "Request failed" : resp.error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -847,7 +879,10 @@ public class LoginManager : MonoBehaviour
|
||||
void OnDestroy()
|
||||
{
|
||||
if (instance == this)
|
||||
{
|
||||
SceneManager.sceneLoaded -= OnSceneLoaded;
|
||||
StopKeepalive();
|
||||
}
|
||||
}
|
||||
|
||||
void StartKeepalive()
|
||||
@@ -947,8 +982,7 @@ public class LoginManager : MonoBehaviour
|
||||
InvalidateStoredSession();
|
||||
SetBusy(false);
|
||||
|
||||
if (error_txt != null)
|
||||
error_txt.text = string.IsNullOrEmpty(message) ? "Session expired. Please sign in again." : message;
|
||||
ShowAuthMessage(string.IsNullOrEmpty(message) ? "Session expired. Please sign in again." : message);
|
||||
|
||||
Scene active = SceneManager.GetActiveScene();
|
||||
if (active.buildIndex != 0 && active.name != "Intro")
|
||||
|
||||
Reference in New Issue
Block a user