Added a forgot password system

This commit is contained in:
Anthony Berg 2020-09-12 18:05:10 +01:00
parent 33f664f307
commit 10008e1698
7 changed files with 1340 additions and 14 deletions

View File

@ -3,6 +3,7 @@
<component name="ContentModelUserStore"> <component name="ContentModelUserStore">
<attachedFolders /> <attachedFolders />
<explicitIncludes> <explicitIncludes>
<Path>Assets</Path>
<Path>Library/PackageCache/com.unity.collab-proxy@1.3.9</Path> <Path>Library/PackageCache/com.unity.collab-proxy@1.3.9</Path>
<Path>Library/PackageCache/com.unity.ext.nunit@1.0.0</Path> <Path>Library/PackageCache/com.unity.ext.nunit@1.0.0</Path>
<Path>Library/PackageCache/com.unity.ide.rider@1.2.1</Path> <Path>Library/PackageCache/com.unity.ide.rider@1.2.1</Path>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,77 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using TMPro;
public class ForgotPassword : MonoBehaviour
{
public TMP_InputField email; //This is for the email text input.
public Button submit; //This is the button used to submit forgot password.
private bool CheckIsEmpty() //This checks if the strings are empty.
{
var strings = new List<string> {email.text}; //This puts all of the text boxes into an array.
string check = ""; //This is used for the check, the ZWSP is TMP's way of identifying nothing as null.
if (strings.Contains(check)) //If any of the inputs are null.
{
return true;
}
return false;
}
void InteractableForm(bool decision)
{
email.interactable = decision;
enabled = decision;
}
// Start is called before the first frame update
void Start()
{
submit.onClick.AddListener(delegate
{
StartCoroutine(ForgotPasswordForm());
});
}
// Update is called once per frame
void Update()
{
if (CheckIsEmpty()) //This checks if all of the inputs are empty.
{
submit.interactable = false; //If they are empty, disable the register button.
}
else
{
submit.interactable = true; //If all of them are filled, then allow the user to register.
}
}
IEnumerator ForgotPasswordForm()
{
InteractableForm(false);
List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
//POST Data
formData.Add(new MultipartFormDataSection("email", email.text)); //For the email.
UnityWebRequest www = UnityWebRequest.Post(Domain.subDomain("includes/reset-request.inc.php"), formData); //This initiates the post request.
yield return www.SendWebRequest(); //This sends the post request.
if (www.isNetworkError || www.isHttpError) //This checks for an error with the server.
{
Debug.Log(www.error); //This prints the error.
}
else
{
Debug.Log(www.downloadHandler.text); //This sends the error code or if it worked on the server side.
InteractableForm(true);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0e5cf5a41b0c9f54c802c605cd3165b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +1,25 @@
using System.Collections; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
using UnityEngine.UI; using UnityEngine.UI;
using TMPro; using TMPro;
using Newtonsoft.Json;
class LoginInformation
{
public string user;
public bool success;
public string errors;
}
public class Login : MonoBehaviour public class Login : MonoBehaviour
{ {
public TMP_InputField username; //This is for the username text input. public TMP_InputField username; //This is for the username text input.
public TMP_InputField password; //This is for the password text input. public TMP_InputField password; //This is for the password text input.
public Button login; //This is the button used to register. public Button login; //This is the button used to log in.
private bool CheckIsEmpty() //This checks if the strings are empty. private bool CheckIsEmpty() //This checks if the strings are empty.
{ {
@ -56,7 +65,7 @@ public class Login : MonoBehaviour
IEnumerator LoginForm() IEnumerator LoginForm()
{ {
InteractableForm(false); InteractableForm(false); //This disables the form.
List<IMultipartFormSection> formData = new List<IMultipartFormSection>(); List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
//POST Data //POST Data
@ -73,16 +82,17 @@ public class Login : MonoBehaviour
} }
else else
{ {
string status = www.downloadHandler.text; string status = www.downloadHandler.text; //This downloads the data from the server.
Debug.Log(status); //This sends the error code or if it worked on the server side. LoginInformation information = JsonConvert.DeserializeObject<LoginInformation>(status); //This deserializes the JSON string to a class.
if (status == "Success")
if (information.success) //If the user has successfully logged in.
{ {
UserManager.username = username.text; UserManager.username = information.user; //This sets the logged in username.
UnityEngine.SceneManagement.SceneManager.LoadScene(1); UnityEngine.SceneManagement.SceneManager.LoadScene(1); //Loads the menu scene.
} }
InteractableForm(true); InteractableForm(true); // This enables the form again.
} }
} }

View File

@ -16,15 +16,26 @@ public class LoginUIHandler : MonoBehaviour
public GameObject registerUI; public GameObject registerUI;
public Button backButtonRegister; public Button backButtonRegister;
//Forgot Password page
public GameObject forgotPasswordUI;
public Button backButtonForgotPassword;
void GoToRegister() void GoToRegister()
{ {
loginUI.SetActive(false); loginUI.SetActive(false);
registerUI.SetActive(true); registerUI.SetActive(true);
} }
void GoToForgotPassword()
{
loginUI.SetActive(false);
forgotPasswordUI.SetActive(true);
}
void GoBack() void GoBack()
{ {
registerUI.SetActive(false); registerUI.SetActive(false);
forgotPasswordUI.SetActive(false);
loginUI.SetActive(true); loginUI.SetActive(true);
} }
@ -32,6 +43,8 @@ public class LoginUIHandler : MonoBehaviour
void Start() void Start()
{ {
register.onClick.AddListener(GoToRegister); register.onClick.AddListener(GoToRegister);
forgotPassword.onClick.AddListener(GoToForgotPassword);
backButtonRegister.onClick.AddListener(GoBack); backButtonRegister.onClick.AddListener(GoBack);
backButtonForgotPassword.onClick.AddListener(GoBack);
} }
} }

View File

@ -1,2 +1,2 @@
m_EditorVersion: 2020.1.4f1 m_EditorVersion: 2020.1.5f1
m_EditorVersionWithRevision: 2020.1.4f1 (fa717bb873ec) m_EditorVersionWithRevision: 2020.1.5f1 (e025938fdedc)