mirror of
https://github.com/smyalygames/monopoly.git
synced 2025-05-18 06:14:10 +02:00
Added a forgot password system
This commit is contained in:
parent
33f664f307
commit
10008e1698
1
.idea/.idea.Monopoly/.idea/indexLayout.xml
generated
1
.idea/.idea.Monopoly/.idea/indexLayout.xml
generated
@ -3,6 +3,7 @@
|
||||
<component name="ContentModelUserStore">
|
||||
<attachedFolders />
|
||||
<explicitIncludes>
|
||||
<Path>Assets</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.ide.rider@1.2.1</Path>
|
||||
|
File diff suppressed because it is too large
Load Diff
77
Assets/Scripts/login/ForgotPassword.cs
Normal file
77
Assets/Scripts/login/ForgotPassword.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/login/ForgotPassword.cs.meta
Normal file
11
Assets/Scripts/login/ForgotPassword.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e5cf5a41b0c9f54c802c605cd3165b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,16 +1,25 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
class LoginInformation
|
||||
{
|
||||
public string user;
|
||||
public bool success;
|
||||
public string errors;
|
||||
}
|
||||
|
||||
public class Login : MonoBehaviour
|
||||
{
|
||||
|
||||
public TMP_InputField username; //This is for the username 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.
|
||||
{
|
||||
@ -56,7 +65,7 @@ public class Login : MonoBehaviour
|
||||
|
||||
IEnumerator LoginForm()
|
||||
{
|
||||
InteractableForm(false);
|
||||
InteractableForm(false); //This disables the form.
|
||||
|
||||
List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
|
||||
//POST Data
|
||||
@ -73,16 +82,17 @@ public class Login : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
string status = www.downloadHandler.text;
|
||||
Debug.Log(status); //This sends the error code or if it worked on the server side.
|
||||
string status = www.downloadHandler.text; //This downloads the data from the server.
|
||||
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;
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(1);
|
||||
UserManager.username = information.user; //This sets the logged in username.
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(1); //Loads the menu scene.
|
||||
}
|
||||
|
||||
InteractableForm(true);
|
||||
InteractableForm(true); // This enables the form again.
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,14 @@ public class LoginUIHandler : MonoBehaviour
|
||||
public GameObject loginUI;
|
||||
public Button register;
|
||||
public Button forgotPassword;
|
||||
|
||||
|
||||
//Register page
|
||||
public GameObject registerUI;
|
||||
public Button backButtonRegister;
|
||||
|
||||
//Forgot Password page
|
||||
public GameObject forgotPasswordUI;
|
||||
public Button backButtonForgotPassword;
|
||||
|
||||
void GoToRegister()
|
||||
{
|
||||
@ -22,9 +26,16 @@ public class LoginUIHandler : MonoBehaviour
|
||||
registerUI.SetActive(true);
|
||||
}
|
||||
|
||||
void GoToForgotPassword()
|
||||
{
|
||||
loginUI.SetActive(false);
|
||||
forgotPasswordUI.SetActive(true);
|
||||
}
|
||||
|
||||
void GoBack()
|
||||
{
|
||||
registerUI.SetActive(false);
|
||||
forgotPasswordUI.SetActive(false);
|
||||
loginUI.SetActive(true);
|
||||
}
|
||||
|
||||
@ -32,6 +43,8 @@ public class LoginUIHandler : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
register.onClick.AddListener(GoToRegister);
|
||||
forgotPassword.onClick.AddListener(GoToForgotPassword);
|
||||
backButtonRegister.onClick.AddListener(GoBack);
|
||||
backButtonForgotPassword.onClick.AddListener(GoBack);
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
m_EditorVersion: 2020.1.4f1
|
||||
m_EditorVersionWithRevision: 2020.1.4f1 (fa717bb873ec)
|
||||
m_EditorVersion: 2020.1.5f1
|
||||
m_EditorVersionWithRevision: 2020.1.5f1 (e025938fdedc)
|
||||
|
Loading…
x
Reference in New Issue
Block a user