Пример #1
0
        public IEnumerator SigninRequest(string username, string password)
        {
            WWWForm form = new WWWForm();

            form.AddField("Username", username, Encoding.UTF8);
            form.AddField("Password", password, Encoding.UTF8);
            UnityWebRequest www = UnityWebRequest.Post("https://ebelder.pythonanywhere.com/signin", form);

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                _parsedLoginSignRequest = JsonUtility.FromJson <ParsedLoginSignRequest>(www.downloadHandler.text);
                Debug.Log(_parsedLoginSignRequest.status);
            }
        }
Пример #2
0
        public IEnumerator LoginRequest(string username, string password)
        {
            //On crée un JSON qui va être envoyé dans la requete
            WWWForm form = new WWWForm();

            form.AddField("Username", username, Encoding.UTF8);
            form.AddField("Password", password, Encoding.UTF8);

            //On envoie notre requete avec le JSON appelé form
            UnityWebRequest www = UnityWebRequest.Post("https://ebelder.pythonanywhere.com/login", form);

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
                yield return(null);
            }
            else
            {
                //On parse le contenu de la réponse dans une classe afin de pouvoir y accéder
                _parsedLoginSignRequest = JsonUtility.FromJson <ParsedLoginSignRequest>(www.downloadHandler.text);
                if (_parsedLoginSignRequest.status.Equals("OK"))
                {
                    Debug.Log("Hello User " + username);
                    StaticLoginSigninClass.gameWon        = _parsedLoginSignRequest.gameWon;
                    StaticLoginSigninClass.playerKilled   = _parsedLoginSignRequest.playerKilled;
                    StaticLoginSigninClass.coins          = _parsedLoginSignRequest.coins;
                    StaticLoginSigninClass.itemOwned      = _parsedLoginSignRequest.itemOwned;
                    StaticLoginSigninClass.playerUsername = username;
                    SceneManager.LoadScene("_masterScene");
                }
                else
                {
                    Debug.Log(_parsedLoginSignRequest.status);
                }
            }
        }