public static AuthenticationAnswer GetPreviousAnswer()
    {
        string previousAnswer   = PlayerPrefs.GetString("previousAnswer");
        AuthenticationAnswer aa = previousAnswer == "" ? AuthenticationAnswer.NeverAsked : (AuthenticationAnswer)System.Enum.Parse(typeof(AuthenticationAnswer), previousAnswer);

        return(aa);
    }
    public static void InitializeSocial(bool forceUI, AfterAuthenticateD afterSuccess = null, AfterAuthenticateD afterFailure = null, MonoBehaviour mb = null)
    {
        AuthenticationAnswer aa = GetPreviousAnswer();

        if (!Authenticated && aa == AuthenticationAnswer.NeverAsked && mb != null)
        {
            ScreenAsk sa = mb.gameObject.AddComponent <ScreenAsk>();
            Destroy(mb);
            sa.PrepareMe(delegate() {
                CarSmasherSocial.SaveAnswerForAuthentication(CarSmasherSocial.AuthenticationAnswer.Accepted);
                sa.gameObject.AddComponent <ScreenSplash>();
                Destroy(sa);
            }, delegate() {
                CarSmasherSocial.SaveAnswerForAuthentication(CarSmasherSocial.AuthenticationAnswer.Denied);
                sa.gameObject.AddComponent <ScreenSplash>();
                Destroy(sa);
            });
        }
        else if (!Authenticated && (aa == AuthenticationAnswer.Accepted || forceUI))
        {
            Social.localUser.Authenticate((bool success) => {
                Authenticated = success;
                SaveAnswerForAuthentication(success ? AuthenticationAnswer.Accepted : AuthenticationAnswer.Denied);
                if (Authenticated)
                {
                    if (afterSuccess != null)
                    {
                        afterSuccess();
                    }
                }
                else
                {
                    if (afterFailure != null)
                    {
                        afterFailure();
                    }
                }
            });
        }
        else
        {
            if (afterFailure != null)
            {
                afterFailure();
            }
        }
    }
Esempio n. 3
0
        public static AuthenticationAnswer Authenticate(string email, string password)
        {
            List <RESTParameter> restParameters = new List <RESTParameter>();

            var body = new { email = email, password = password };

            restParameters.Add(new RESTParameter(RESTParameterType.POST, JsonConvert.SerializeObject(body)));

            RESTResponse restResponse = CallRESTService.CallService(Parameters.URLs.Auth.Signin, restParameters, CallModeServiceREST.POST);

            AuthenticationAnswer authenticationAnswer = new AuthenticationAnswer();

            if (restResponse.Error != null)
            {
                authenticationAnswer.Success = false;

                switch (restResponse.HTTPStatuCode)
                {
                case 401:
                    authenticationAnswer.ErrorType = AuthenticationErrorType.Unauthorized;
                    break;

                default:
                    authenticationAnswer.ErrorType = AuthenticationErrorType.Unknow;
                    break;
                }
            }
            else
            {
                Tools.CheckBodyResponse(restResponse.Body);

                authenticationAnswer.Token = ((JObject)JsonConvert.DeserializeObject(restResponse.Body)).SelectToken("token").ToObject <string>();

                Context.Token = authenticationAnswer.Token;

                authenticationAnswer.Success = true;
            }

            return(authenticationAnswer);
        }
        private void Authenticate(PasswordBox pwdPassword)
        {
            if (String.IsNullOrEmpty(Login) || String.IsNullOrEmpty(pwdPassword.Password))
            {
                // MessageBox.Show("Please, enter login and password before");

                return;
            }

            AuthenticationAnswer authenticationAnswer = AccountControler.Authenticate(Login, pwdPassword.Password);

            pwdPassword.Clear();

            Token = authenticationAnswer.Token;

            if (!String.IsNullOrEmpty(Context.Token))
            {
                MyAccount = AccountControler.GetMyAccount();
            }
            else
            {
                // MessageBox.Show("Authentication error : " + authenticationAnswer.ErrorType);
            }
        }
 public static void SaveAnswerForAuthentication(AuthenticationAnswer answer)
 {
     PlayerPrefs.SetString("previousAnswer", answer.ToString());
 }