Add forgot username/password buttons (sends email right now only, everything else needs to be finished on the server rn)

This commit is contained in:
2026-01-23 19:54:59 -07:00
parent 563f4fa711
commit e361ab34de
7 changed files with 3233 additions and 74 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,62 @@
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class AccountForgotDetails : MonoBehaviour
{
[SerializeField] internal TMP_Text forgotDetailsTitleText;
[SerializeField] private TMP_Text forgotDetailsStatusText;
[SerializeField] private TMP_InputField forgotDetailsEmailInput;
[SerializeField] private TMP_InputField forgotDetailsVerifyCodeInput;
[SerializeField] internal Button forgotDetailsBackButton;
[SerializeField] internal Button forgotDetailsSubmitButton;
internal int mode = 0;
void Awake()
{
forgotDetailsBackButton.onClick.AddListener(() =>
{
forgotDetailsBackButton.interactable = false;
forgotDetailsSubmitButton.interactable = false;
mode = 0;
forgotDetailsTitleText.text = "";
AccountHandler.instance.SwitchPanel(2);
});
forgotDetailsSubmitButton.onClick.AddListener(() => ForgotDetails());
}
void OnEnable()
{
forgotDetailsEmailInput.text = "";
forgotDetailsVerifyCodeInput.text = "";
}
async void ForgotDetails()
{
forgotDetailsBackButton.interactable = false;
forgotDetailsSubmitButton.interactable = false;
WWWForm dataForm = new();
dataForm.AddField("email", forgotDetailsEmailInput.text);
dataForm.AddField("verifyCode", forgotDetailsVerifyCodeInput.text);
forgotDetailsVerifyCodeInput.text = "";
using UnityWebRequest request = UnityWebRequest.Post(mode == 0 ? Endpoints.ACCOUNT_FORGOT_USERNAME_ENDPOINT : Endpoints.ACCOUNT_FORGOT_PASSWORD_ENDPOINT, dataForm);
request.SetRequestHeader("Requester", "BerryDashClient");
request.SetRequestHeader("ClientVersion", Application.version);
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
await request.SendWebRequest();
if (request.downloadHandler.text == null)
{
forgotDetailsBackButton.interactable = true;
forgotDetailsSubmitButton.interactable = true;
Tools.UpdateStatusText(forgotDetailsStatusText, "Failed to make HTTP request", Color.red);
return;
}
var jsonResponse = JObject.Parse(request.downloadHandler.text);
if ((bool)jsonResponse["success"]) Tools.UpdateStatusText(forgotDetailsStatusText, "An email has been sent to your inbox", Color.green);
else Tools.UpdateStatusText(forgotDetailsStatusText, (string)jsonResponse["message"], Color.red);
forgotDetailsBackButton.interactable = true;
forgotDetailsSubmitButton.interactable = true;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8e73b40d4fe6b41dd9b73f1334fd3e78

View File

@@ -12,6 +12,7 @@ public class AccountHandler : MonoBehaviour
[SerializeField] private AccountChangeUsername accountChangeUsername;
[SerializeField] private AccountChangePassword accountChangePassword;
[SerializeField] private AccountRefreshLogin accountRefreshLogin;
[SerializeField] internal AccountForgotDetails accountForgotDetails;
void Awake()
{
@@ -42,6 +43,7 @@ public class AccountHandler : MonoBehaviour
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 1:
accountLoggedIn.gameObject.SetActive(false);
@@ -51,6 +53,7 @@ public class AccountHandler : MonoBehaviour
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 2:
accountLoggedIn.gameObject.SetActive(false);
@@ -60,6 +63,7 @@ public class AccountHandler : MonoBehaviour
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 3:
accountLoggedIn.gameObject.SetActive(false);
@@ -69,6 +73,7 @@ public class AccountHandler : MonoBehaviour
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 4:
accountLoggedIn.gameObject.SetActive(false);
@@ -78,6 +83,7 @@ public class AccountHandler : MonoBehaviour
accountChangeUsername.gameObject.SetActive(true);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 5:
accountLoggedIn.gameObject.SetActive(false);
@@ -87,6 +93,7 @@ public class AccountHandler : MonoBehaviour
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(true);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 6:
accountLoggedIn.gameObject.SetActive(false);
@@ -96,6 +103,17 @@ public class AccountHandler : MonoBehaviour
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(true);
accountForgotDetails.gameObject.SetActive(false);
break;
case 7:
accountLoggedIn.gameObject.SetActive(false);
accountLoggedOut.gameObject.SetActive(false);
accountLogin.gameObject.SetActive(false);
accountRegister.gameObject.SetActive(false);
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(true);
break;
}
foreach (CustomColorObject customColorObject in FindObjectsByType<CustomColorObject>(FindObjectsSortMode.None)) customColorObject.SetColor();
@@ -107,6 +125,7 @@ public class AccountHandler : MonoBehaviour
{
if (accountChangePassword.gameObject.activeSelf || accountChangeUsername.gameObject.activeSelf || accountRefreshLogin.gameObject.activeSelf) SwitchPanel(0);
else if (accountLogin.gameObject.activeSelf || accountRegister.gameObject.activeSelf) SwitchPanel(1);
else if (accountForgotDetails.gameObject.activeSelf) accountForgotDetails.forgotDetailsBackButton.onClick.Invoke();
else await SceneManager.LoadSceneAsync("MainMenu");
}
}

View File

@@ -1,5 +1,5 @@
using System.Numerics;
using Newtonsoft.Json.Linq;
using System.Numerics;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
@@ -10,6 +10,8 @@ public class AccountLogin : MonoBehaviour
[SerializeField] private TMP_Text loginPanelStatusText;
[SerializeField] private TMP_InputField loginUsernameInput;
[SerializeField] private TMP_InputField loginPasswordInput;
[SerializeField] private Button forgotUsernameButton;
[SerializeField] private Button forgotPasswordButton;
[SerializeField] private Button loginBackButton;
[SerializeField] private Button loginSubmitButton;
@@ -17,6 +19,22 @@ public class AccountLogin : MonoBehaviour
{
loginBackButton.onClick.AddListener(() => AccountHandler.instance.SwitchPanel(1));
loginSubmitButton.onClick.AddListener(() => SubmitLogin());
forgotUsernameButton.onClick.AddListener(() =>
{
AccountHandler.instance.SwitchPanel(7);
AccountHandler.instance.accountForgotDetails.mode = 0;
AccountHandler.instance.accountForgotDetails.forgotDetailsTitleText.text = "Forgot username";
AccountHandler.instance.accountForgotDetails.forgotDetailsBackButton.interactable = true;
AccountHandler.instance.accountForgotDetails.forgotDetailsSubmitButton.interactable = true;
});
forgotPasswordButton.onClick.AddListener(() =>
{
AccountHandler.instance.SwitchPanel(7);
AccountHandler.instance.accountForgotDetails.mode = 1;
AccountHandler.instance.accountForgotDetails.forgotDetailsTitleText.text = "Forgot password";
AccountHandler.instance.accountForgotDetails.forgotDetailsBackButton.interactable = true;
AccountHandler.instance.accountForgotDetails.forgotDetailsSubmitButton.interactable = true;
});
}
void OnEnable()

View File

@@ -64,6 +64,7 @@ public class AccountRegister : MonoBehaviour
dataForm.AddField("email", registerEmailInput.text);
dataForm.AddField("password", registerPasswordInput.text);
dataForm.AddField("verifyCode", registerVerifyCodeInput.text);
registerVerifyCodeInput.text = "";
using UnityWebRequest request = UnityWebRequest.Post(Endpoints.ACCOUNT_REGISTER_ENDPOINT, dataForm);
request.SetRequestHeader("Requester", "BerryDashClient");
request.SetRequestHeader("ClientVersion", Application.version);

View File

@@ -19,4 +19,6 @@ public class Endpoints
public static readonly string ACCOUNT_LOGIN_ENDPOINT = ACCOUNT_ENDPOINT + "/login";
public static readonly string ACCOUNT_REGISTER_ENDPOINT = ACCOUNT_ENDPOINT + "/register";
public static readonly string ACCOUNT_SAVE_ENDPOINT = ACCOUNT_ENDPOINT + "/save";
public static readonly string ACCOUNT_FORGOT_USERNAME_ENDPOINT = BASE_URL + "/account/forgot-username";
public static readonly string ACCOUNT_FORGOT_PASSWORD_ENDPOINT = BASE_URL + "/account/forgot-password";
}