Esempio n. 1
0
    ///初始化User
    public IEnumerator sInitUser()
    {
        //OperatingDB.Instance.GetUser();
        if (IsLoggedin())
        {
            ///刷新accessToken
            WWWHelp          www = new WWWHelp();
            UserRefreshToken urt = new UserRefreshToken();
            urt.accessToken  = User.Instance.accessToken;
            urt.refreshToken = User.Instance.refreshToken;
            urt.client       = GlobalConst.ClientFlag + "-" + User.Instance.deviceFlag;
            string parm = JsonConvert.SerializeObject(urt);
            //yield return StartCoroutine(www.WWWPostLoad(GlobalConst.UserRefreshTokenPath, parm));
            if (www.CheckWWW())
            {
                UserRefreshTokenResponse urtr = JsonConvert.DeserializeObject <UserRefreshTokenResponse>(www.text);
                if (urtr.result.code == 0)
                {
                    User.Instance.accessToken  = urtr.accessToken;
                    User.Instance.refreshToken = urtr.refreshToken;
                    SaveUser();
                    yield return(0);

                    //yield return StartCoroutine(GetUserInfo());
                    if (string.IsNullOrEmpty(nickname))
                    {
                        //UIManager.Instance.SetVisible(UIName.PanelSetNickname, true);
                    }
                }
                else
                {
                    Debug.Log("resultCode:" + urtr.result.code + "  " + urtr.result.description);
                }
            }
            www.Dispose();
        }
    }
Esempio n. 2
0
    public IEnumerator sGetUserInfo()
    {
        if (!IsLoggedin())
        {
            yield break;
        }
        WWWHelp www = new WWWHelp();

        //yield return StartCoroutine(www.WWWGetLoad(GlobalConst.USERPATH + User.Instance.id + GlobalConst.GETUSERINFO, new string[] { "Authorization" }, new string[] { User.Instance.accessToken }));
        if (www.CheckWWW())
        {
            UserInfoResponse uir = JsonConvert.DeserializeObject <UserInfoResponse>(www.text);
            if (uir.result.code == 0)
            {
                Debug.Log("获取用户信息成功");
                if (!uir.user.nickname.Equals(nickname))
                {
                    nickname = uir.user.nickname;
                    SaveUser();
                }
            }
            else if (uir.result.code == 1000)
            {
                Debug.Log("resultCode:" + uir.result.code + "  " + uir.result.description);
            }
            else if (uir.result.code == 1004)
            {
                Debug.Log("resultCode:" + uir.result.code + "  " + uir.result.description);
            }
            else
            {
                Debug.Log("resultCode:" + uir.result.code + "  " + uir.result.description);
            }
        }
        www.Dispose();
    }
Esempio n. 3
0
    IEnumerator sButtonLoginOnClick()
    {
        if (MyWindow.window.IsSubmit)
        {
            yield break;
        }
        Debug.Log("登录按钮");
        string email    = MyWindow.window.GetInputAccount();
        string password = MyWindow.window.GetInputPassword();

        //验证账号密码格式
        if (Validation())
        {
            password = EncryptionPass(password);
            UserLogin userlogin = new UserLogin(email, password, GlobalConst.ClientFlag + "-" + User.Instance.deviceFlag, GlobalConst.ClientVersion);
            string    parmJson  = JsonConvert.SerializeObject(userlogin);
            // UIManager.Instance.ShowWaitLoading(true);
            MyWindow.window.IsSubmit = true;

            //Json parmJson = Json.Decode(JsonConvert.SerializeObject(userlogin)) as Json;

            //yield return StartCoroutine(wwwh.WWWPostLoad(GlobalConst.UserLoginPath, parmJson));
            MyWindow.window.IsSubmit = false;
            // UIManager.Instance.ShowWaitLoading(false);
            if (wwwh.CheckWWW())
            {
                //根据返回数据继续处理
                UserLoginResponse loginResponse = JsonConvert.DeserializeObject <UserLoginResponse>(wwwh.text);
                Debug.Log(loginResponse.result.code);
                if (loginResponse.result.code == 0)
                {
                    //登录成功,
                    Debug.Log("登录成功");
                    MyWindow.window.ClearInputAccountValue();
                    MyWindow.window.ClearInputPasswordValue();
                    User user = User.CreateInstance("User") as User;
                    user.SetUser(loginResponse.user.userId, loginResponse.user.nickname, loginResponse.user.username, loginResponse.accessToken, loginResponse.refreshToken);
                    user.SaveUser();
                    //SetPopupType(PopupType.CenterToTop);
                    //UIManager.Instance.SetVisible(UIName.PanelQuickLogin, false);
                    //UIManager.Instance.ShowMessageBox("登录成功", 2.5f);
                    //添加app通知用户Key值
                    //OneSignal.SendTags(new Dictionary<string, string>() { { "UserId", User.Instance.id }, { "Login", "true" } });
                    //if (UIManager.Instance.IsVisible(UIName.panelMyPlans))
                    //    PanelMyPlans.mPanelMyPlans.LoadMyPlans();
                }
                else if (loginResponse.result.code == 1004)
                {
                    //用户名不存在
                    Debug.Log("用户名不存在");
                    //mLabel_ErrorMessage.text = "*用户名不存在";
                    //mLabel_ErrorMessage.gameObject.SetActive(true);
                }
                else if (loginResponse.result.code == 1005)
                {
                    //用户名密码错误z
                    Debug.Log("用户名密码错误");
                    //mLabel_ErrorMessage.text = "*用户名或密码错误";
                    //mLabel_ErrorMessage.gameObject.SetActive(true);
                }
                else if (loginResponse.result.code == 1008)
                {
                    //未验证邮箱
                    Debug.Log("未验证邮箱");
                    //mLabel_ErrorMessage.text = "*未验证邮箱";
                    //mLabel_ErrorMessage.gameObject.SetActive(true);
                }
            }
        }
    }