private static AsyncHTTPClient.DoneCallback WrapLoginCallback(AssetStoreClient.DoneLoginCallback callback) { return(delegate(AsyncHTTPClient job) { string text = job.text; if (!job.IsSuccess()) { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; AssetStoreClient.sLoginErrorMessage = ((job.responseCode < 200 || job.responseCode >= 300) ? "Failed to login - please retry" : text); } else if (text.StartsWith("<!DOCTYPE")) { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; AssetStoreClient.sLoginErrorMessage = "Failed to login"; } else { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_IN; if (text.Contains("@")) { AssetStoreClient.ActiveSessionID = AssetStoreClient.SavedSessionID; } else { AssetStoreClient.ActiveSessionID = text; } if (AssetStoreClient.RememberSession) { AssetStoreClient.SavedSessionID = AssetStoreClient.ActiveSessionID; } } callback(AssetStoreClient.sLoginErrorMessage); }); }
public static void Logout() { AssetStoreClient.UserIconUrl = null; AssetStoreClient.ActiveSessionID = string.Empty; AssetStoreClient.SavedSessionID = string.Empty; AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_OUT; }
internal static void LoginWithRememberedSession(AssetStoreClient.DoneLoginCallback callback) { if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS) { DebugUtils.LogWarning("Tried to login with remembered session while already in progress of logging in"); return; } AssetStoreClient.sLoginState = AssetStoreClient.LoginState.IN_PROGRESS; AssetStoreClient.sLoginErrorMessage = null; if (!AssetStoreClient.RememberSession) { AssetStoreClient.SavedSessionID = string.Empty; } Uri uri = new Uri(string.Format("{0}/login?reuse_session={1}&unityversion={2}&toolversion={3}&xunitysession={4}", new object[] { AssetStoreClient.AssetStoreUrl, AssetStoreClient.SavedSessionID, Uri.EscapeDataString(Application.unityVersion), Uri.EscapeDataString("V5.0.0"), "26c4202eb475d02864b40827dfff11a14657aa41" })); AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient(); AssetStoreClient.Pending pending = new AssetStoreClient.Pending() { conn = assetStoreWebClient, id = "login", callback = AssetStoreClient.WrapLoginCallback(callback) }; AssetStoreClient.pending.Add(pending); assetStoreWebClient.Headers.Add("Accept", "application/json"); assetStoreWebClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AssetStoreClient.DownloadStringCallback); try { assetStoreWebClient.DownloadStringAsync(uri, pending); } catch (WebException webException) { pending.ex = webException; AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; } }
static AssetStoreClient() { AssetStoreClient.s_AssetStoreUrl = null; AssetStoreClient.s_AssetStoreSearchUrl = null; AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_OUT; AssetStoreClient.sLoginErrorMessage = null; ServicePointManager.ServerCertificateValidationCallback = ((object obj, X509Certificate x509Certificate, X509Chain x509Chain, SslPolicyErrors sslPolicyErrors) => true); }
static AssetStoreClient() { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_OUT; AssetStoreClient.sLoginErrorMessage = null; AssetStoreClient.s_PendingLargeFiles = new List <AssetStoreClient.LargeFilePending>(); AssetStoreClient.s_UploadingLargeFile = null; AssetStoreClient.pending = new List <AssetStoreClient.Pending>(); ServicePointManager.ServerCertificateValidationCallback = ((object obj, X509Certificate x509Certificate, X509Chain x509Chain, SslPolicyErrors sslPolicyErrors) => true); }
internal static void LoginWithCredentials(string username, string password, bool rememberMe, AssetStoreClient.DoneLoginCallback callback) { if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS) { Debug.LogError((object)"Tried to login with credentials while already in progress of logging in"); } else { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.IN_PROGRESS; AssetStoreClient.RememberSession = rememberMe; string str = AssetStoreClient.AssetStoreUrl + "/login?skip_terms=1"; AssetStoreClient.sLoginErrorMessage = (string)null; AsyncHTTPClient asyncHttpClient = new AsyncHTTPClient(str.Replace("http://", "https://")); asyncHttpClient.postData = "user="******"&pass="******"X-Unity-Session"] = "26c4202eb475d02864b40827dfff11a14657aa41" + AssetStoreClient.GetToken(); asyncHttpClient.doneCallback = AssetStoreClient.WrapLoginCallback(callback); asyncHttpClient.Begin(); } }
internal static void LoginWithCredentials(string username, string password, bool rememberMe, AssetStoreClient.DoneLoginCallback callback) { if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS) { DebugUtils.LogWarning("Tried to login with credentials while already in progress of logging in"); return; } AssetStoreClient.sLoginState = AssetStoreClient.LoginState.IN_PROGRESS; AssetStoreClient.RememberSession = rememberMe; AssetStoreClient.sLoginErrorMessage = null; Uri uri = new Uri(string.Format("{0}/login", AssetStoreClient.AssetStoreUrl)); AssetStoreWebClient assetStoreWebClient = new AssetStoreWebClient(); NameValueCollection nameValueCollection = new NameValueCollection() { { "user", username }, { "pass", password }, { "unityversion", Application.unityVersion }, { "toolversion", "V5.0.0" }, { "license_hash", AssetStoreClient.GetLicenseHash() }, { "hardware_hash", AssetStoreClient.GetHardwareHash() } }; AssetStoreClient.Pending pending = new AssetStoreClient.Pending() { conn = assetStoreWebClient, id = "login", callback = AssetStoreClient.WrapLoginCallback(callback) }; AssetStoreClient.pending.Add(pending); assetStoreWebClient.Headers.Add("Accept", "application/json"); assetStoreWebClient.UploadValuesCompleted += new UploadValuesCompletedEventHandler(AssetStoreClient.UploadValuesCallback); try { assetStoreWebClient.UploadValuesAsync(uri, "POST", nameValueCollection, pending); } catch (WebException webException) { pending.ex = webException; AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; } }
internal static void LoginWithRememberedSession(AssetStoreClient.DoneLoginCallback callback) { if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS) { Debug.LogError((object)"Tried to login with remembered session while already in progress of logging in"); } else { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.IN_PROGRESS; if (!AssetStoreClient.RememberSession) { AssetStoreClient.SavedSessionID = string.Empty; } string _toUrl = AssetStoreClient.AssetStoreUrl + "/login?skip_terms=1&reuse_session=" + AssetStoreClient.SavedSessionID; AssetStoreClient.sLoginErrorMessage = (string)null; AsyncHTTPClient asyncHttpClient = new AsyncHTTPClient(_toUrl); asyncHttpClient.header["X-Unity-Session"] = "26c4202eb475d02864b40827dfff11a14657aa41" + AssetStoreClient.GetToken(); asyncHttpClient.doneCallback = AssetStoreClient.WrapLoginCallback(callback); asyncHttpClient.Begin(); } }
private static AssetStoreClient.DoneCallback WrapLoginCallback(AssetStoreClient.DoneLoginCallback callback) { return((AssetStoreResponse resp) => { AssetStoreClient.UserIconUrl = null; int num = -1; if (resp.HttpHeaders != null) { num = Array.IndexOf <string>(resp.HttpHeaders.AllKeys, "X-Unity-Reason"); } if (!resp.ok) { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; AssetStoreClient.sLoginErrorMessage = (num < 0 ? resp.HttpErrorMessage ?? "Failed communication" : resp.HttpHeaders.Get(num)); AssetStoreClient.sLoginErrorMessage = (resp.HttpStatusCode != 401 ? AssetStoreClient.sLoginErrorMessage : "The email and/or password you entered are incorrect. Please try again."); AssetStoreClient.sLoginErrorMessage = (resp.HttpStatusCode != 500 ? AssetStoreClient.sLoginErrorMessage : "Server error. Possibly due to excess incorrect login attempts. Try again later."); DebugUtils.LogError(resp.HttpErrorMessage ?? "Unknown http error"); } else if (!resp.data.StartsWith("<!DOCTYPE")) { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_IN; JSONValue jSONValue = JSONParser.SimpleParse(resp.data); AssetStoreClient.ActiveSessionID = jSONValue["xunitysession"].AsString(false); AssetStoreClient.UserIconUrl = jSONValue.Get("keyimage.icon").AsString(false); if (AssetStoreClient.RememberSession) { AssetStoreClient.SavedSessionID = AssetStoreClient.ActiveSessionID; } } else { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; AssetStoreClient.sLoginErrorMessage = (num < 0 ? "Failed to login" : resp.HttpHeaders.Get(num)); DebugUtils.LogError(resp.data ?? "no data"); } callback(AssetStoreClient.sLoginErrorMessage); }); }
private static AssetStoreClient.DoneCallback WrapLoginCallback(AssetStoreClient.DoneLoginCallback callback) { return(delegate(AssetStoreResponse resp) { AssetStoreClient.UserIconUrl = null; int num = -1; if (resp.HttpHeaders != null) { num = Array.IndexOf <string>(resp.HttpHeaders.AllKeys, "X-Unity-Reason"); } if (!resp.ok) { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; AssetStoreClient.sLoginErrorMessage = ((num < 0) ? "Failed communication" : resp.HttpHeaders.Get(num)); DebugUtils.LogError(resp.HttpErrorMessage ?? "Unknown http error"); } else if (resp.data.StartsWith("<!DOCTYPE")) { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; AssetStoreClient.sLoginErrorMessage = ((num < 0) ? "Failed to login" : resp.HttpHeaders.Get(num)); DebugUtils.LogError(resp.data ?? "no data"); } else { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_IN; JSONValue jSONValue = JSONParser.SimpleParse(resp.data); AssetStoreClient.ActiveSessionID = jSONValue["xunitysession"].AsString(false); AssetStoreClient.UserIconUrl = jSONValue.Get("keyimage.icon").AsString(false); if (AssetStoreClient.RememberSession) { AssetStoreClient.SavedSessionID = AssetStoreClient.ActiveSessionID; } } callback(AssetStoreClient.sLoginErrorMessage); }); }
public static void Logout() { AssetStoreClient.ActiveSessionID = string.Empty; AssetStoreClient.SavedSessionID = string.Empty; AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_OUT; }
private static AsyncHTTPClient.DoneCallback WrapLoginCallback(AssetStoreClient.DoneLoginCallback callback) { return delegate(AsyncHTTPClient job) { string text = job.text; if (!job.IsSuccess()) { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; AssetStoreClient.sLoginErrorMessage = ((job.responseCode < 200 || job.responseCode >= 300) ? "Failed to login - please retry" : text); } else { if (text.StartsWith("<!DOCTYPE")) { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGIN_ERROR; AssetStoreClient.sLoginErrorMessage = "Failed to login"; } else { AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_IN; if (text.Contains("@")) { AssetStoreClient.ActiveSessionID = AssetStoreClient.SavedSessionID; } else { AssetStoreClient.ActiveSessionID = text; } if (AssetStoreClient.RememberSession) { AssetStoreClient.SavedSessionID = AssetStoreClient.ActiveSessionID; } } } callback(AssetStoreClient.sLoginErrorMessage); }; }
internal static void LoginWithRememberedSession(AssetStoreClient.DoneLoginCallback callback) { if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS) { Debug.LogError("Tried to login with remembered session while already in progress of logging in"); return; } AssetStoreClient.sLoginState = AssetStoreClient.LoginState.IN_PROGRESS; if (!AssetStoreClient.RememberSession) { AssetStoreClient.SavedSessionID = string.Empty; } string toUrl = AssetStoreClient.AssetStoreUrl + "/login?skip_terms=1&reuse_session=" + AssetStoreClient.SavedSessionID; AssetStoreClient.sLoginErrorMessage = null; AsyncHTTPClient asyncHTTPClient = new AsyncHTTPClient(toUrl); asyncHTTPClient.header["X-Unity-Session"] = "26c4202eb475d02864b40827dfff11a14657aa41" + AssetStoreClient.GetToken(); asyncHTTPClient.doneCallback = AssetStoreClient.WrapLoginCallback(callback); asyncHTTPClient.Begin(); }
internal static void LoginWithCredentials(string username, string password, bool rememberMe, AssetStoreClient.DoneLoginCallback callback) { if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS) { Debug.LogError("Tried to login with credentials while already in progress of logging in"); return; } AssetStoreClient.sLoginState = AssetStoreClient.LoginState.IN_PROGRESS; AssetStoreClient.RememberSession = rememberMe; string text = AssetStoreClient.AssetStoreUrl + "/login?skip_terms=1"; AssetStoreClient.sLoginErrorMessage = null; AsyncHTTPClient asyncHTTPClient = new AsyncHTTPClient(text.Replace("http://", "https://")); asyncHTTPClient.postData = "user="******"&pass="******"X-Unity-Session"] = "26c4202eb475d02864b40827dfff11a14657aa41" + AssetStoreClient.GetToken(); asyncHTTPClient.doneCallback = AssetStoreClient.WrapLoginCallback(callback); asyncHTTPClient.Begin(); }
public static void Logout() { AssetStoreClient.ActiveSessionID = ""; AssetStoreClient.SavedSessionID = ""; AssetStoreClient.sLoginState = AssetStoreClient.LoginState.LOGGED_OUT; }