Example #1
0
        public void LoginWithGoogle()
        {
            TacoManager.LoginPanelObject.SetActive(true);//if from register panel
            TacoManager.OpenMessage(TacoConfig.TacoLoginStatusMessage00);
            Debug.Log("internet: " + Application.internetReachability);
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                TacoManager.CloseMessage();
                TacoManager.OpenModalLoginFailedPanel(TacoConfig.TacoLoginStatusNoInternet);
                return;
            }

            Action <string> onSuccess = (string data) => {
                TacoManager.CloseMessage();
                GoogleDeviceInfo r = JsonUtility.FromJson <GoogleDeviceInfo> (data);
                CodeDisplayPanel.SetActive(true);
                CodeDisplayPanel.transform.Find("Main/Code").GetComponent <InputField> ().text = r.user_code;
                deviceInfo = r;
                //testing
                TextEditor te = new TextEditor();
                te.text = deviceInfo.user_code;
                te.SelectAll();
                te.Copy();
            };

            Action <string, string> onFail = (string data, string error) => {
                TacoManager.CloseMessage();
                TacoManager.OpenModalLoginFailedPanel(error);
            };

            StartCoroutine(ApiManager.Instance.RequestDeviceAdnUserCode(authorizationDeviceEndpoint, clientID, onSuccess, onFail));
        }
Example #2
0
        private IEnumerator PollRequestToGoogle(GoogleDeviceInfo deviceData)
        {
            bool polling  = true;
            int  nbOfPoll = 9;

            while (polling)
            {
                Action <string> onSuccess = (string accessData) => {
                    Debug.Log("access data: " + accessData);
                    AccessData result = JsonUtility.FromJson <AccessData> (accessData);
                    if (!string.IsNullOrEmpty(result.access_token))
                    {
                        polling = false;

                        Debug.Log("login google");
                        Action <string> successUserInfo = (string userInfo) => {
                            TacoManager.CloseMessage();

                            Debug.Log(userInfo);
                            LoginResult r = JsonUtility.FromJson <LoginResult> (userInfo);
                            if (r.success)
                            {
                                TacoManager.OpenMessage(TacoConfig.TacoLoginStatusMessage01);
                                TacoManager.CreateUser(r);
                                BalanceManager.Instance.SetRemainingValue(r.remainingClaim, r.login_count);
                                if (r.msg == "in")
                                {
                                    if (r.free == "free")
                                    {
                                        //TacoManager.OpenModal("Login success", "Welcome back to game taco! You get " + r.score_tokens + " taco token from free play!");
                                    }
                                    else
                                    {
                                        if (r.free == "enough")
                                        {
                                            //TacoManager.OpenModal("Login success", "Welcome back to game taco! You've got too many taco tokens today! Please try again tomorrow.");
                                        }
                                        else
                                        {
                                            TacoManager.OpenHowToPlayPanel();
                                        }
                                    }
                                }
                                else
                                {
                                    if (r.msg == "anotherSocial")
                                    {
                                        if (r.free == "free")
                                        {
                                            //TacoManager.OpenModal("Login success", "You get " + "6" + " taco token for login today! And " + r.score_tokens + " taco token from free play!");
                                        }
                                        else
                                        {
                                            TacoManager.OpenModalRegisterPanel(TacoManager.User.name);
                                        }
                                    }
                                    else
                                    {
                                        if (r.free == "free")
                                        {
                                            //TacoManager.OpenModal("Login success", "You get " + r.value + " taco token for login today! And " + r.score_tokens + " taco token from free play!");
                                        }
                                        else
                                        {
                                            if (!TacoManager.GetPanel("SuccessRegister").activeSelf)
                                            {
                                                TacoManager.OpenModalDailyTokenPanel(r.value);
                                            }
                                        }
                                    }
                                }

                                // clean up the login panel
                                Init();
                            }
                            else
                            {
                                TacoManager.CloseMessage();
                                TacoManager.OpenModalLoginFailedPanel(TacoConfig.Error);
                            }
                        };
                        Action <string, string> failUserInfo = (string userInfo, string error) => {
                            //TacoManager.CloseMessage();
                            //TacoManager.OpenModalLoginFailedPanel(error);
                            Debug.Log(userInfo);
                            if (!string.IsNullOrEmpty(userInfo))
                            {
                                SystemError r = JsonUtility.FromJson <SystemError> (userInfo);
                                if (r.verErr)
                                {
                                    //version error
                                    TacoManager.CloseMessage();
                                    TacoManager.OpenModalIncorrectVersionPanel(r.message);
                                }
                                else
                                {
                                    TacoManager.CloseMessage();
                                    string msg = r.message;
                                    if (string.IsNullOrEmpty(msg))
                                    {
                                        msg = TacoConfig.TacoLoginErrorEmailPassword;
                                    }
                                    TacoManager.OpenModalLoginFailedPanel(msg);
                                }
                            }
                            else
                            {
                                TacoManager.CloseMessage();
                                TacoManager.OpenModalLoginFailedPanel(TacoConfig.TacoLoginErrorEmailPassword);
                            }
                        };
                        StartCoroutine(ApiManager.Instance.LoginGoogle(result.access_token, result.id_token, ReferenceCodeInput.text, successUserInfo, failUserInfo));
                    }
                    else if (nbOfPoll < 0)
                    {
                        polling = false;
                        TacoManager.CloseMessage();
                        TacoManager.OpenModalLoginFailedPanel(TacoConfig.Error);
                    }
                    nbOfPoll--;
                };
                Action <string, string> onFail = (string data, string error) => {
                    nbOfPoll--;
                    if (nbOfPoll < 0)
                    {
                        polling = false;
                        TacoManager.CloseMessage();
                        TacoManager.OpenModalLoginFailedPanel(error);
                    }
                };
                StartCoroutine(ApiManager.Instance.PollGoogleAuthorization("https://www.googleapis.com/oauth2/v4/token", clientID, clientSecret, deviceData.device_code, "http://oauth.net/grant_type/device/1.0", deviceData.interval, onSuccess, onFail));
                yield return(new WaitForSeconds(deviceData.interval));
            }
        }