IEnumerator LogIn()
    {
        messageText.text = "";

        username = usernameText.text;
        password = passwordText.text;
        verified = "0";

        if (username == "" || password == "")
        {
            messageText.text = "Please complete all fields.";
        }
        else
        {
            WWWForm form = new WWWForm();
            form.AddField("username", username);
            form.AddField("password", password);
            form.AddField("verified", verified);
            if (ValidateIPv4(ipAddress))
            {
                UnityWebRequest www = UnityWebRequest.Post("http://" + ipAddress + "/register2/login.php", form);

                yield return(www.SendWebRequest());

                Debug.Log("Response:" + www.downloadHandler.text);
                message2Text.text = www.downloadHandler.text;
                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                    messageText.text = www.error;
                }
                else
                {
                    if (message2Text.text == "The username or password you entered is incorrect")
                    {
                        messageText.text = "The username or password you entered is incorrect";
                    }
                    else if (message2Text.text == "This account not yet been verified.")
                    {
                        messageText.text = "This account not yet been verified.";
                    }
                    else
                    {
                        loggedText.text = "Account logged in:"
                                          + "\n " + " " + "\n " + www.downloadHandler.text
                                          + "\n " + " " + "\n " + "Your game can start here...";
                        LoginPan.SetActive(false);
                        SwitchPan.SetActive(false);
                        IpObj.SetActive(false);
                        loggedText.gameObject.SetActive(true);
                    }
                }
            }
            else
            {
                messageText.text = "Please enter a valid ip address.";
            }
        }
    }
Example #2
0
        private string BuildCacheAndReturnIp()
        {
            var newObj = new IpObj
            {
                Ip         = GetCurrentIp(),
                Expiration = DateTimeOffset.UtcNow.AddMinutes(5),
            };

            cache.AddOrUpdate(IP_CACHE_KEY, newObj, (x, y) => newObj);

            return(newObj.Ip);
        }