// Helper function for login callbacks
        static AsyncHTTPClient.DoneCallback WrapLoginCallback(DoneLoginCallback callback)
        {
            return(delegate(IAsyncHTTPClient job) {
                // We're logging in
                string msg = job.text;
                if (!job.IsSuccess())
                {
                    AssetStoreClient.sLoginState = LoginState.LOGIN_ERROR;
                    AssetStoreClient.sLoginErrorMessage = job.responseCode >= 200 && job.responseCode < 300 ? msg : "Failed to login - please retry";
                }
                else if (msg.StartsWith("<!DOCTYPE"))     // TODO: Expose status line in job
                {
                    AssetStoreClient.sLoginState = LoginState.LOGIN_ERROR;
                    AssetStoreClient.sLoginErrorMessage = "Failed to login";
                }
                else
                {
                    AssetStoreClient.sLoginState = LoginState.LOGGED_IN;
                    if (msg.Contains("@"))     // login with reused session id returns the user email
                    {
                        AssetStoreClient.ActiveSessionID = SavedSessionID;
                    }
                    else
                    {
                        AssetStoreClient.ActiveSessionID = msg;
                    }

                    if (RememberSession)
                    {
                        SavedSessionID = ActiveSessionID;
                    }
                }
                callback(AssetStoreClient.sLoginErrorMessage);
            });
        }
        /*
         * Tries to login using a remembered session
         */
        internal static void LoginWithRememberedSession(DoneLoginCallback callback)
        {
            if (sLoginState == LoginState.IN_PROGRESS)
            {
                Debug.LogError("Tried to login with remembered session while already in progress of logging in");
                return;
            }
            sLoginState = LoginState.IN_PROGRESS;

            // Make sure the session is not present if we're not allowed to use it
            if (!RememberSession)
            {
                SavedSessionID = "";
            }

            string url = AssetStoreUrl + "/login?skip_terms=1&reuse_session=" + SavedSessionID;

            AssetStoreClient.sLoginErrorMessage = null;
            AsyncHTTPClient client = new AsyncHTTPClient(url);

            client.header["X-Unity-Session"] = kUnauthSessionID + GetToken();
            client.doneCallback = WrapLoginCallback(callback);
            client.Begin();
        }
        internal static void LoginWithCredentials(string username, string password, bool rememberMe, DoneLoginCallback callback)
        {
            if (sLoginState == LoginState.IN_PROGRESS)
            {
                Debug.LogError("Tried to login with credentials while already in progress of logging in");
                return;
            }
            sLoginState     = LoginState.IN_PROGRESS;
            RememberSession = rememberMe;
            string url = AssetStoreUrl + "/login?skip_terms=1";

            AssetStoreClient.sLoginErrorMessage = null;
            AsyncHTTPClient client = new AsyncHTTPClient(url.Replace("http://", "https://"));

            client.postData = "user="******"&pass="******"X-Unity-Session"] = kUnauthSessionID + GetToken();
            client.doneCallback = WrapLoginCallback(callback);
            client.Begin();
        }
Esempio n. 4
0
    public static void LoginWithCredentials(string username, string password, bool rememberMe, DoneLoginCallback callback)
    {
        Type doneLoginCallbackType;
        var  doneLoginCallback = CreateCallbackDelegate("DoneLoginCallback", callback, out doneLoginCallbackType);

        s_Instance.GetRuntimeType().Invoke("LoginWithCredentials", username.Param(), password.Param(), rememberMe.Param(), new Parameter(doneLoginCallback, doneLoginCallbackType));
    }