Esempio n. 1
0
    private IEnumerator DeleteProfileRequest(string token)
    {
        UnityWebRequest requestDeleteProfile = UnityWebRequest.Delete("https://unitrivia.herokuapp.com/api/profile");

        requestDeleteProfile.SetRequestHeader("jwt", token);
        yield return(requestDeleteProfile.SendWebRequest());

        //Debug.Log("ResponseCode: " + requestDeleteProfile.responseCode);

        if (requestDeleteProfile.result == UnityWebRequest.Result.ConnectionError)
        {
            //Debug.Log("ERROR CONNECTION:" + requestDeleteProfile.result);

            ErrorDataScript.setErrorText("Error de conexión");
            ErrorDataScript.setButtonMode(1);
            SceneManager.LoadScene("Error Scene", LoadSceneMode.Additive);
        }
        else if (requestDeleteProfile.responseCode != 200)
        {
            //Debug.Log("ERROR DELETE:" + requestDeleteProfile.downloadHandler.text);
            ServerReturn result = ServerReturn.CreateFromJSON(requestDeleteProfile.downloadHandler.text);

            ErrorDataScript.setErrorText(result.message);
            ErrorDataScript.setButtonMode(1);
            SceneManager.LoadScene("Error Scene", LoadSceneMode.Additive);
        }
        else
        {
            //Debug.Log("EXITO DELETE:" + requestDeleteProfile.downloadHandler.text);

            SuccessDataScript.setSuccessText("Usuario eliminado correctamente!");
            SuccessDataScript.setReturnScene("Login Scene");
            SceneManager.LoadScene("Success Scene", LoadSceneMode.Additive);
        }
    }
Esempio n. 2
0
    private IEnumerator RegisterRequest(string username, string password, string email, string preg, string res)
    {
        UnityWebRequest requestRegister = UnityWebRequest.Post("https://unitrivia.herokuapp.com/api/register", "");

        requestRegister.SetRequestHeader("username", username);
        requestRegister.SetRequestHeader("password", password);
        requestRegister.SetRequestHeader("email", email);
        requestRegister.SetRequestHeader("preg", preg);
        requestRegister.SetRequestHeader("res", res);
        yield return(requestRegister.SendWebRequest());

        Debug.Log("ResponseCode: " + requestRegister.responseCode);

        if (requestRegister.result == UnityWebRequest.Result.ConnectionError)
        {
            Debug.Log("ERROR CONNECTION:" + requestRegister.result);

            ErrorDataScript.setErrorText("Error de conexión");
            ErrorDataScript.setButtonMode(1);
            SceneManager.LoadScene("Error Scene", LoadSceneMode.Additive);
        }
        else if (requestRegister.responseCode != 200)
        {
            Debug.Log("ERROR REGISTRO:" + requestRegister.downloadHandler.text);
            ServerReturn result = ServerReturn.CreateFromJSON(requestRegister.downloadHandler.text);

            ErrorDataScript.setErrorText(result.message);
            ErrorDataScript.setButtonMode(1);
            SceneManager.LoadScene("Error Scene", LoadSceneMode.Additive);
        }
        else
        {
            Debug.Log("EXITO REGISTRO:" + requestRegister.downloadHandler.text);
            //Guardar Token usuario

            SuccessDataScript.setSuccessText("Registro realizado correctamente!");
            SuccessDataScript.setReturnScene("Login Scene");
            SceneManager.LoadScene("Success Scene", LoadSceneMode.Additive);
        }
    }
Esempio n. 3
0
    private IEnumerator ChangePasswordRequest(string username, string answer, string password)
    {
        UnityWebRequest requestChangePassword = UnityWebRequest.Post("https://unitrivia.herokuapp.com/api/login/recover/password", "");

        requestChangePassword.SetRequestHeader("username", username);
        requestChangePassword.SetRequestHeader("res", answer);
        requestChangePassword.SetRequestHeader("newpassword", password);
        yield return(requestChangePassword.SendWebRequest());

        Debug.Log("ResponseCode: " + requestChangePassword.responseCode);

        if (requestChangePassword.result == UnityWebRequest.Result.ConnectionError)
        {
            Debug.Log("ERROR CONNECTION:" + requestChangePassword.result);

            ErrorDataScript.setErrorText("Error de conexión");
            ErrorDataScript.setButtonMode(1);
            SceneManager.LoadScene("Error Scene", LoadSceneMode.Additive);
        }
        else if (requestChangePassword.responseCode != 200)
        {
            Debug.Log("ERROR LOGIN:"******"Error Scene", LoadSceneMode.Additive);
        }
        else
        {
            Debug.Log("EXITO LOGIN:"******"Cambio realizado correctamente!");
            SuccessDataScript.setReturnScene("Login Scene");
            SceneManager.LoadScene("Success Scene", LoadSceneMode.Additive);
        }
    }