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:
62
Assets/Scripts/AccountMenu/AccountForgotDetails.cs
Normal file
62
Assets/Scripts/AccountMenu/AccountForgotDetails.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user