Exemple #1
0
    /// <summary>
    /// 서버에 로그인 정보를 전송하고 로그인 성공 시 <see cref="_userInfo"/> 멤버에 정보를 저장하는 코루틴.
    /// </summary>
    private IEnumerator LoginCoroutine()
    {
        string userId   = IdInputField.text;
        string password = PwInputField.text;

        WWWForm loginForm = new WWWForm();

        loginForm.AddField("Input_user", userId);
        loginForm.AddField("Input_pass", password);

        _clientInfo.GetComponent <ClientInfo>().LodingCanvas.GetComponent <LoadingCanvasBehaviour>().ShowLodingCanvas();
        // 로그인 정보를 서버에 POST
        using (UnityWebRequest www = UnityWebRequest.Post("http://ec2-13-125-7-2.ap-northeast-2.compute.amazonaws.com:31337/capstone/login_session.php", loginForm))
        {
            // POST 전송
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                ShowToastOnUiThread("Failed to sign in. Cannot connect to the server.");
                _clientInfo.GetComponent <ClientInfo>().LodingCanvas.GetComponent <LoadingCanvasBehaviour>().HideLodingCanvas();
                Debug.Log(www.error);
            }
            else
            {
                // 서버에서 Json 응답으로 유저 정보를 UserInfo 오브젝트에 적용
                string responseJsonString = www.downloadHandler.text;

                JsonLoginData loginInfo = JsonUtility.FromJson <JsonLoginData>(responseJsonString);
                _userInfo = GameObject.FindGameObjectWithTag("UserInfo").GetComponent <UserInfo>();

                _userInfo.SessionId = loginInfo.sessionID;
                _userInfo.UserName  = loginInfo.user_name;
                _userInfo.UserId    = loginInfo.user_id;
                _userInfo.Point     = loginInfo.point;

                // 서버로부터 현재 로그인된 user_id와 user_name를 받아온다
                if (loginInfo.user_id == "")
                {
                    ShowToastOnUiThread("ID or Password is incorrect.");
                    _clientInfo.GetComponent <ClientInfo>().LodingCanvas.GetComponent <LoadingCanvasBehaviour>().HideLodingCanvas();
                }
                else
                {
                    Debug.Log("succeeded to sign in");
                    PwInputField.text = "";
                    _clientInfo.GetComponent <ClientInfo>().OriginalValuesAreSet = false;
                    SceneManager.LoadScene("InApp");
                }
            }
        }
    }
Exemple #2
0
    void OnEnable()
    {
        jsonQRdata    = null;
        jsonLogindata = null;

        encoded             = new Texture2D(256, 256);
        Global._stopRequest = false;

        //StartCoroutine (OnGetRequest());
        OnGetRequest();



        Debug.Log("login start!");
    }
Exemple #3
0
    public static void ReloadFamilyData(string tmp, int type)
    {
        switch (type)
        {
        case 1:
            jsonQRdata = JsonMapper.ToObject <JsonQRCodeData>(tmp);
            break;

        case 2:
            jsonLogindata = JsonMapper.ToObject <JsonLoginData>(tmp);
            break;

        default:
            break;
        }
    }
Exemple #4
0
    void OnEnable()
    {
        jsonModel          = null;
        jsonQRdata         = null;
        jsonLogindata      = null;
        login_success_flag = false;
        login_first_flag   = false;

        jsonUserScanData = new JsonUserScanData();
        json_length      = (int)GetFileSize(scandata_json);
        byData           = new byte[json_length];
        data_str         = new string[24];
        //upload_raw = new Thread(thread_raw);//上传数据线程初始化

        upload_raw = new Thread(new ParameterizedThreadStart(thread_raw));


        if (Global.isLoadLastDataPage)
        {
            Debug.Log("DATA_LoadDataFromService");
            showUserInfo("昵称:" + Global.name, "ID:微信用户" + Global.id.ToString());
            DATA_LoadDataFromService();
        }
        else
        {
            showAddress();
            NGUITools.SetActive(qrwindow, false);


            if (Global.isLogin)
            {
                Debug.Log("UserDataProce isLogin = "******"昵称:" + Global.name, "ID:微信用户" + Global.id.ToString());
                onUploadUserBaseInfo(Global.token);
                ParseLocalDataFromKaola();
                UploadData2Service();
            }
            else
            {
                NGUITools.SetActive(childTitleWindow, false);
                Debug.Log("ParseLocalDataFromKaola");
                ParseLocalDataFromKaola();
                showQRCodeUI();
                getQRCode();
            }
        }
    }
Exemple #5
0
 public void Read()
 {
     try
     {
         FileStream file = new FileStream("Assets/Guider/UserData/json.txt", FileMode.Open);
         file.Seek(0, SeekOrigin.Begin);
         file.Read(byData, 0, Global.leng_json); //byData传进来的字节数组,用以接受FileStream对象中的数据,第2个参数是字节数组中开始写入数据的位置,它通常是0,表示从数组的开端文件中向数组写数据,最后一个参数规定从文件读多少字符.
         jsondata = System.Text.Encoding.Default.GetString(byData);
         Debug.Log(jsondata);
         jsonUserdata = JsonMapper.ToObject <JsonLoginData>(System.Text.Encoding.UTF8.GetString(byData));
         file.Close();
     }
     catch (IOException e)
     {
         Console.WriteLine(e.ToString());
     }
 }
/* private void displayUserData()
 * {
 *
 *   GameObject.Find("UI Root/Camera/login_panel/Window1/Label").GetComponent<UILabel>().text = "bir:"+jsonLogindata.birthday+
 *       "address"+jsonLogindata.address;
 *
 *
 *   throw new NotImplementedException();
 * }*/

    public static void ReloadFamilyData(string tmp, int type)
    {
        switch (type)
        {
        case 1:
            jsonQRdata = JsonMapper.ToObject <JsonQRCodeData>(tmp);
            break;

        case 2:
            jsonLogindata = JsonMapper.ToObject <JsonLoginData>(tmp);
            GameObject.Find("UI Root/Camera/login_panel/Window1/Label").GetComponent <UILabel>().text = "code = " + jsonLogindata.code;
            break;

        default:
            break;
        }
    }
Exemple #7
0
    void SetResult(string text)
    {
        Debug.Log("SetResult...................... text: " + text);
        jsonLoginResult = JsonUtility.FromJson <JsonLoginData>(text);

        if (jsonLoginResult == null || jsonLoginResult.result.Count == 0)
        {
            SetDebbugText("Login failed " + usernameInserted + " pass: "******"Licence not available for this app");
            GotoLogin();
        }
        else if (deviceName.Length > 1)
        {
            SetLicencia(jsonLoginResult.result[0].licencia);
        }
        else
        {
            StartCoroutine(Register());
        }
    }
Exemple #8
0
    IEnumerator LoadScene(string sceneName)
    {
        yield return(null);

        // scene 로드 작업을 시작한다.
        AsyncOperation loadSceneOperation = SceneManager.LoadSceneAsync(sceneName);

        loadSceneOperation.allowSceneActivation = false;

        var uerInfo = GameObject.FindGameObjectWithTag("UserInfo").GetComponent <UserInfo>();

        // 로딩 화면에 유저 아이디를 표시한다.
        WWWForm loginInfoForm = new WWWForm();

        loginInfoForm.AddField("id", uerInfo.SessionId);

        using (UnityWebRequest www = UnityWebRequest.Post("http://ec2-13-125-7-2.ap-northeast-2.compute.amazonaws.com:31337/capstone/login_info.php", loginInfoForm))
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log(www.downloadHandler.text);

                string        responseJsonString = www.downloadHandler.text;
                JsonLoginData dataList           = JsonUtility.FromJson <JsonLoginData>(responseJsonString);

                WelcomeText.GetComponent <Text>().text = "Welcome,\n" + dataList.user_name + "!";
                Debug.Log(WelcomeText.GetComponent <Text>().text);
            }
        }

        // 이미지를 사용해 프로그레스 바 표시
        float timer = 0.0f;

        while (!loadSceneOperation.isDone)
        {
            yield return(null);

            timer += Time.deltaTime;

            if (loadSceneOperation.progress >= 0.9f)
            {
                ProgressBar.fillAmount = Mathf.Lerp(ProgressBar.fillAmount, 1f, timer);

                if (ProgressBar.fillAmount == 1.0f)
                {
                    // 완료됐으면 scene 표시.
                    loadSceneOperation.allowSceneActivation = true;
                }
            }
            else
            {
                ProgressBar.fillAmount = Mathf.Lerp(ProgressBar.fillAmount, loadSceneOperation.progress, timer);
                if (ProgressBar.fillAmount >= loadSceneOperation.progress)
                {
                    timer = 0f;
                }
            }
        }
    }