We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
using System; using System.Collections; using UnityEngine; using UnityEngine.Networking; public class LoginHttps : MonoBehaviour { public void Login(string userName, string password, string url, Action onSuccess, Action onFailed) { // TODO: do somethings to validate user name & password from client //... StartCoroutine(IELogin(userName, password, url, onSuccess, onFailed)); } IEnumerator IELogin(string userName, string password, string url, Action onSuccess, Action onFailed) { WWWForm form = new WWWForm(); form.AddField("uid", userName); form.AddField("pass", password); using (UnityWebRequest www = UnityWebRequest.Post(url, form)) { yield return www.SendWebRequest(); if (www.isDone) { string response = www.downloadHandler.text; // response is a json string like: {code:0,err:"wrong password"} if (!string.IsNullOrEmpty(response)) { ResponseData result = JsonUtility.FromJson(response); if (result != null) { if (result.code == 1) { Debug.Log("Login Successfully."); onSuccess?.Invoke(); } else { Debug.LogError($"Login Failure: {result.err}"); onFailed?.Invoke(); } } } else { Debug.LogError("Something wrong from response, check your backend!"); onFailed?.Invoke(); } } else { Debug.LogError(www.error); // Network error or something wrong which can not post to url. onFailed?.Invoke(); } } } [System.Serializable] class ResponseData { public int code; // 0: Login Failed, 1: Login Success public string err; // Such as: Username is not exist, Wrong password... } }
2.2K Point(s)
1.2K Point(s)
313 Point(s)
178 Point(s)
138 Point(s)
Input your email to receive reset password link, or if you remember your password, you can click