Exemple #1
0
        public void Login()
        {
            var email    = EmailInput.GetComponent <InputField> ().text;
            var password = PasswordInput.GetComponent <InputField> ().text;
            // toggle returns a bool
            bool autoLoginBool = AutoLoginToggle.GetComponent <Toggle> ().isOn;

            // Unity doesn't allow Bool as a preference type, using int
            int autoLoginInt = 0;

            if (autoLoginBool)
            {
                autoLoginInt = 1;
            }

            TacoManager.OpenMessage(TacoConfig.TacoLoginStatusMessage00);

            //TODO: Verify valid email syntax
            if (email == string.Empty || password == string.Empty)
            {
                TacoManager.CloseMessage();
                TacoManager.OpenModalLoginFailedPanel(TacoConfig.TacoLoginErrorMessage00);
            }
            else
            {
                Action <string> success = (string data) => {
                    LoginResult r = JsonUtility.FromJson <LoginResult> (data);
                    if (r.success)
                    {
                        Debug.Log("login login_count " + r.login_count);
                        BalanceManager.Instance.SetRemainingValue(r.remainingClaim, r.login_count);
                        TacoManager.SetPreference(UserPreferences.autoLogin, autoLoginInt);
                        TacoManager.SetPreferenceString(UserPreferences.userToken, r.token);

                        TacoManager.OpenMessage(TacoConfig.TacoLoginStatusMessage01);
                        TacoManager.CreateUser(r);

                        if (r.msg == "in")
                        {
                            if (r.free == "free")
                            {
                                //Debug.LogError("No longer implemented");
                                //TacoManager.OpenModal("Login success", "Welcome back to game taco! You get " + r.score_tokens + " taco token from free play!");
                            }
                            else
                            {
                                if (r.free == "enough")
                                {
                                    Debug.LogError("No longer implemented");
                                    //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.free == "free")
                            {
                                Debug.LogError("No longer implemented");
                                //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);
                                }
                                else
                                {
                                    TacoManager.OpenModalRegisterPanel(TacoManager.User.name);
                                }
                            }
                        }
                        //ApiManager.Instance.OpenConnection();
                        //ApiManager.Instance.SendData(r.userName + string.Empty);
                        Init();
                    }
                    else
                    {
                        TacoManager.CloseMessage();
                        TacoManager.OpenModalLoginFailedPanel(TacoConfig.TacoLoginErrorEmailPassword);
                    }
                };

                Action <string, string> fail = (string data, string error) => {
                    if (!string.IsNullOrEmpty(data))
                    {
                        SystemError r = JsonUtility.FromJson <SystemError> (data);
                        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);
                    }

                    if (!string.IsNullOrEmpty(error))
                    {
                        Debug.Log("Error : " + error);
                    }
                };

                StartCoroutine(ApiManager.Instance.Login(email, password, success, fail));
            }
        }
Exemple #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));
            }
        }
Exemple #3
0
        public void GetSession(string token)
        {
            TacoManager.OpenMessage(TacoConfig.TacoLoginStatusMessage00);

            Action <string> success = (string data) => {
                SessionResult r = JsonUtility.FromJson <SessionResult> (data);
                if (r.success)
                {
                    Debug.Log("session: " + data);
                    BalanceManager.Instance.SetRemainingValue(r.remainingClaim, r.login_count);
                    TacoManager.OpenMessage(TacoConfig.TacoLoginStatusMessage01);
                    TacoManager.UpdateUser(r, token);
                    if (r.msg == "in")
                    {
                        //Debug.LogWarning("No longer implemented");
                    }
                    else
                    {
                        TacoManager.OpenModalDailyTokenPanel(r.value);
                    }
                }
                else
                {
                    TacoManager.CloseMessage();
                    TacoManager.SetPreferenceString(UserPreferences.userToken, null);
                    TacoManager.SetPreference(UserPreferences.autoLogin, 0);
                    TacoManager.ShowPanel(PanelNames.LoginPanel);

                    if (!string.IsNullOrEmpty(r.message))
                    {
                        TacoManager.OpenModalLoginFailedPanel(r.message);
                    }
                }
            };

            Action <string, string> fail = (string data, string error) => {
                if (!string.IsNullOrEmpty(data))
                {
                    try {
                        SystemError r = JsonUtility.FromJson <SystemError> (data);
                        if (r.verErr)
                        {
                            //version error
                            TacoManager.OpenModalIncorrectVersionPanel(r.message);
                        }
                        else
                        {
                            string msg = r.message;
                            if (string.IsNullOrEmpty(msg))
                            {
                                msg = TacoConfig.TacoLoginErrorEmailPassword;
                            }
                            TacoManager.OpenModalLoginFailedPanel(msg);
                        }
                    } catch (Exception) {
                        TacoManager.OpenModalLoginFailedPanel(TacoConfig.Error);
                    }
                }
                else
                {
                    TacoManager.OpenModalLoginFailedPanel(TacoConfig.TacoLoginErrorEmailPassword);
                }
                TacoManager.CloseMessage();
            };
            string url = "api/session/detail/" + TacoSetup.Instance.SiteId;

            StartCoroutine(ApiManager.Instance.GetWithToken(url, success, fail));
        }