Example #1
0
    IEnumerator SendDetails()
    {
        //Debug.Log("SEND DETAILS");
        string registerUserURL = "https://edplus.net/registerUser";
        var    request         = new UnityWebRequest(registerUserURL, "POST");
        SendAuthDetailsJSON sendAuthDetailsJSON = new SendAuthDetailsJSON()
        {
            UserID   = email,
            Password = password
        };
        string json = JsonUtility.ToJson(sendAuthDetailsJSON);

        byte[] bodyRaw = new System.Text.UTF8Encoding().GetBytes(json);
        request.uploadHandler   = new UploadHandlerRaw(bodyRaw);
        request.downloadHandler = new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");
        yield return(request.SendWebRequest());

        while (!request.isDone)
        {
            yield return(null);
        }
        //Debug.Log("Response: " + request.downloadHandler.text);
        SendAuthDetailsJSONResponse sendAuthDetailsJSONResponse = JsonUtility.FromJson <SendAuthDetailsJSONResponse>(request.downloadHandler.text);

        if (sendAuthDetailsJSONResponse.status != "success")
        {
            //Debug.Log(sendAuthDetailsJSONResponse.data);
            if (sendAuthDetailsJSONResponse.data == "EMAIL_EXISTS")
            {
                errorTextSignUp.text = "Email already exists";
                registered           = false;
                loadingScreen.SetActive(false);
                yield return(null);
            }
            else
            {
                errorTextSignUp.text = "Please try again";
                loadingScreen.SetActive(false);
                yield return(null);
            }
        }
        else
        {
            SyncTables.firebaseUID = sendAuthDetailsJSONResponse.data;
            PlayerPrefs.SetString("Username", email);
            PlayerPrefs.SetString("Mail", email);
            PlayerPrefs.SetString("Password", password);
            //Debug.Log("Registration succeeded.");
            registered = true;
            StartCoroutine(SendFirebaseUID());
        }
    }
Example #2
0
    IEnumerator SendDetails()
    {
        //Debug.Log("SEND DETAILS");
        string             forgotPasswordURL  = "https://edplus.net/sendPasswordResetEmail";
        var                request            = new UnityWebRequest(forgotPasswordURL, "POST");
        ForgotPasswordJSON forgotPasswordJSON = new ForgotPasswordJSON()
        {
            Email = Mail.text
        };
        string json = JsonUtility.ToJson(forgotPasswordJSON);

        byte[] bodyRaw = new System.Text.UTF8Encoding().GetBytes(json);
        request.uploadHandler   = (UploadHandler) new UploadHandlerRaw(bodyRaw);
        request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");
        yield return(request.SendWebRequest());

        while (!request.isDone)
        {
            yield return(null);
        }
        //Debug.Log("Response: " + request.downloadHandler.text);
        SendAuthDetailsJSONResponse sendAuthDetailsJSONResponse = JsonUtility.FromJson <SendAuthDetailsJSONResponse>(request.downloadHandler.text);

        if (sendAuthDetailsJSONResponse.status != "success")
        {
            //Debug.Log(sendAuthDetailsJSONResponse.data);
            if (sendAuthDetailsJSONResponse.data == "EMAIL_NOT_FOUND")
            {
                errorText.text = "This Email is not associated with any account. Please check the email entered and try again.";
                yield return(null);
            }
            else
            {
                errorText.text = "Please try again";
                yield return(null);
            }
        }
        else
        {
            Debug.Log(sendAuthDetailsJSONResponse.data);
            instructionsButton.SetActive(true);
        }
    }
Example #3
0
    IEnumerator SendDetails()
    {
        //Debug.Log("SEND DETAILS");
        string loginUserURL = "https://edplus.net/loginUser";
        var    request      = new UnityWebRequest(loginUserURL, "POST");
        SendAuthDetailsJSON sendAuthDetailsJSON = new SendAuthDetailsJSON()
        {
            UserID   = email,
            Password = password
        };
        string json = JsonUtility.ToJson(sendAuthDetailsJSON);

        byte[] bodyRaw = new System.Text.UTF8Encoding().GetBytes(json);
        request.uploadHandler   = new UploadHandlerRaw(bodyRaw);
        request.downloadHandler = new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");
        yield return(request.SendWebRequest());

        while (!request.isDone)
        {
            yield return(null);
        }
        //Debug.Log("Response: " + request.downloadHandler.text);
        SendAuthDetailsJSONResponse sendAuthDetailsJSONResponse = JsonUtility.FromJson <SendAuthDetailsJSONResponse>(request.downloadHandler.text);

        if (request.downloadHandler.text == "" || request.downloadHandler.text == null)
        {
            loadingScreen.SetActive(false);
        }
        if (sendAuthDetailsJSONResponse.status != "success")
        {
            //Debug.Log(sendAuthDetailsJSONResponse.data);
            if (sendAuthDetailsJSONResponse.data == "EMAIL_NOT_FOUND" || sendAuthDetailsJSONResponse.data == "INVALID_PASSWORD")
            {
                errorTextSignIn.text     = "Oops, that's not the correct email/password combination.";
                forgotPasswordText.color = Color.red;
                yield return(null);
            }
            else if (SyncTables.internetLogin == false)
            {
                errorTextSignIn.text = "Not connected to Internet";
            }
            else
            {
                errorTextSignIn.text = "PLease try again";
                yield return(null);
            }
            loadingScreen.SetActive(false);
        }
        else
        {
            //Debug.Log(sendAuthDetailsJSONResponse.data);
            SyncTables.firebaseUID = sendAuthDetailsJSONResponse.data;
            user = email;
            PlayerPrefs.SetString("Username", email);
            PlayerPrefs.SetString("Password", password);
            loggedIn      = true;
            loggedInEmail = true;
            StartCoroutine(GetUID("Email"));
        }
    }