예제 #1
0
    public static IEnumerator RequestRegister(string username, string password, string email, string character, string matricNo, string confirmPassword)
    {
        WWWForm form = new WWWForm();

        form.AddField("username", username);
        form.AddField("password", password);
        form.AddField("password2", confirmPassword);
        form.AddField("email", email);
        form.AddField("character", character);
        form.AddField("matricNo", matricNo);

        string RequestRegisterURL = baseRegisterAPIURL;

        UnityWebRequest registerRequest = UnityWebRequest.Post(RequestRegisterURL, form);

        yield return(registerRequest.SendWebRequest());

        JSONNode registerInfo = JSON.Parse(registerRequest.downloadHandler.text);

        if (registerRequest.isNetworkError || registerRequest.isHttpError)
        {
            Debug.LogError(registerRequest.error);
            MissingInputField.setText(registerInfo["message"]);
            MissingInputField.promptMissingField();
            yield break;
        }
        else if (registerInfo["message"].Equals("Register successfully"))
        {
            RegistrationController.registerSuccessful();
        }
    }
예제 #2
0
    // ------------------------------ AUTHENTICATION ------------------------------ //

    public static IEnumerator RequestLogin(string matricNo, string password)
    {
        WWWForm form = new WWWForm();

        form.AddField("matricNo", matricNo);
        form.AddField("password", password);

        string RequestLoginURL = baseLoginAPIURL;

        UnityWebRequest loginRequest = UnityWebRequest.Post(RequestLoginURL, form);

        yield return(loginRequest.SendWebRequest());

        JSONNode loginInfo = JSON.Parse(loginRequest.downloadHandler.text);

        Debug.Log(loginInfo);

        if (loginRequest.isNetworkError || loginRequest.isHttpError)
        {
            Debug.LogError(loginRequest.error);
            MissingInputField.setText(loginInfo["message"]);
            MissingInputField.promptMissingField();
            yield break;
        }
        else if (loginInfo["message"].Equals("Login successfully"))
        {
            ProgramStateController.loggedIn      = true;
            ProgramStateController.username      = loginInfo["username"];
            ProgramStateController.email         = loginInfo["email"];
            ProgramStateController.characterType = loginInfo["character"];
            ProgramStateController.matricNo      = loginInfo["matricNo"];
            yield return(GetUnlockedStates(loginInfo["matricNo"]));

            LoginController.loginSuccessful();
        }
    }