public void WindowActivated() { if (m_loginProcessData != null && !m_loginProcessData.IsTokenFlow) { LoginProcessData loginProcessData = m_loginProcessData; m_loginProcessData = null; TextBoxDialog dialog = new TextBoxDialog("输入用户登录Token:", "", 256, delegate(string s) { if (s != null) { try { WebManager.Post(m_redirectUri + "/com/oauth2/token", new Dictionary <string, string> { { "code", s.Trim() }, { "client_id", "1unnzwkb8igx70k" }, { "client_secret", "3i5u3j3141php7u" }, { "grant_type", "authorization_code" } }, null, new MemoryStream(), loginProcessData.Progress, delegate(byte[] result) { SettingsManager.ScpboxAccessToken = ((IDictionary <string, object>)WebManager.JsonFromBytes(result))["access_token"].ToString(); loginProcessData.Succeed(this); }, delegate(Exception error) { loginProcessData.Fail(this, error); }); } catch (Exception error2) { loginProcessData.Fail(this, error2); } } else { loginProcessData.Fail(this, null); } }); DialogsManager.ShowDialog(null, dialog); } }
public void Login(CancellableProgress progress, Action success, Action <Exception> failure) { try { if (m_loginProcessData != null) { throw new InvalidOperationException("登陆已经在进程中"); } if (!WebManager.IsInternetConnectionAvailable()) { throw new InvalidOperationException("网络连接错误"); } Logout(); progress.Cancelled += delegate { if (m_loginProcessData != null) { LoginProcessData loginProcessData = m_loginProcessData; m_loginProcessData = null; loginProcessData.Fail(this, null); } }; m_loginProcessData = new LoginProcessData(); m_loginProcessData.Progress = progress; m_loginProcessData.Success = success; m_loginProcessData.Failure = failure; LoginLaunchBrowser(); } catch (Exception obj) { failure(obj); } }
public void LoginLaunchBrowser() { try { LoginDialog login = new LoginDialog(); login.succ = delegate(byte[] a) { StreamReader streamReader = new StreamReader(new MemoryStream(a)); JsonObject json = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(streamReader.ReadToEnd()); int code = int.Parse(json["code"].ToString()); string msg = json["msg"].ToString(); if (code == 200) { JsonObject token = (JsonObject)json["data"]; SettingsManager.ScpboxAccessToken = token["accessToken"].ToString(); DialogsManager.HideAllDialogs(); } else { login.tip.Text = msg; } }; login.fail = delegate(Exception e) { login.tip.Text = e.ToString(); }; DialogsManager.ShowDialog(null, login); } catch (Exception error) { m_loginProcessData.Fail(this, error); } }
public void LoginLaunchBrowser() { try { m_loginProcessData.IsTokenFlow = true; Dictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary.Add("response_type", "token"); dictionary.Add("client_id", "1unnzwkb8igx70k"); dictionary.Add("redirect_uri", "com.candyrufusgames.survivalcraft2://redirect"); WebBrowserManager.LaunchBrowser("https://www.dropbox.com/oauth2/authorize?" + WebManager.UrlParametersToString(dictionary)); } catch (Exception error) { m_loginProcessData.Fail(this, error); } }
public void HandleUri(Uri uri) { if (m_loginProcessData == null) { m_loginProcessData = new LoginProcessData(); m_loginProcessData.IsTokenFlow = true; } LoginProcessData loginProcessData = m_loginProcessData; m_loginProcessData = null; if (loginProcessData.IsTokenFlow) { try { if (!(uri != null) || string.IsNullOrEmpty(uri.Fragment)) { goto IL_00a5; } Dictionary <string, string> dictionary = WebManager.UrlParametersFromString(uri.Fragment.TrimStart('#')); if (!dictionary.ContainsKey("access_token")) { if (dictionary.ContainsKey("error")) { throw new Exception(dictionary["error"]); } goto IL_00a5; } SettingsManager.DropboxAccessToken = dictionary["access_token"]; loginProcessData.Succeed(this); goto end_IL_0038; IL_00a5: throw new Exception("Could not retrieve Dropbox access token."); end_IL_0038 :; } catch (Exception error) { loginProcessData.Fail(this, error); } } }
public void HandleUri(Uri uri) { if (m_loginProcessData == null) { m_loginProcessData = new LoginProcessData(); m_loginProcessData.IsTokenFlow = true; } LoginProcessData loginProcessData = m_loginProcessData; m_loginProcessData = null; if (loginProcessData.IsTokenFlow) { try { if (!(uri != null) || string.IsNullOrEmpty(uri.Fragment)) { throw new Exception("不能接收来自SPMBox的身份验证信息"); } Dictionary <string, string> dictionary = WebManager.UrlParametersFromString(uri.Fragment.TrimStart('#')); if (!dictionary.ContainsKey("access_token")) { if (dictionary.ContainsKey("error")) { throw new Exception(dictionary["error"]); } throw new Exception("不能接收来自SPMBox的身份验证信息"); } SettingsManager.ScpboxAccessToken = dictionary["access_token"]; loginProcessData.Succeed(this); } catch (Exception error) { loginProcessData.Fail(this, error); } } }