public ShopeeOrderPageViewModel() { ShopeeOrderPageLoading = new DelegateCommand(() => { StaticResources.SelectedShopLogin.NewOrderCount = 0; StaticResources.OrderFeature.SelfCount = 0; var bc = Utility.GetToProcessingBillCount(StaticResources.SelectedShopLogin); }); BtCancelGrPrinterTapped = new DelegateCommand(() => { this.TgGrPrinter = "Collapsed"; }); BtOpenPrinterTapped = new DelegateCommand(() => { this.TgGrPrinter = "Visible"; }); wvLoaded = new DelegateCommand <WebView>((s) => { if (s != null) { Uri sale_uri = new Uri(StaticResources.SaleUri); HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); Utility.ClearCookie(filter, sale_uri); HttpCookieManager cookieManager = filter.CookieManager; try { foreach (var ck in StaticResources.SelectedShopLogin.lstLoginCookie) { HttpCookie cookie = new HttpCookie(ck.name, ck.domain[0].Equals('.') ? ck.domain : "." + ck.domain, ck.path); cookie.Value = ck.value; cookieManager.SetCookie(cookie, false); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } new Thread(async() => { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { s.Navigate(sale_uri); }); }).Start(); } }); wvScriptNotify = new DelegateCommand <NotifyEventArgs>((s) => { }); }
public ShopeeChatPageViewModel() { ShopeeChatPageLoading = new DelegateCommand(() => { StaticResources.SelectedShopLogin.NewMessageCount = 0; StaticResources.MessageFeature.SelfCount = 0; }); wvLoaded = new DelegateCommand <WebView>((s) => { if (s != null) { Uri chat_uri = new Uri(StaticResources.ChatUri); HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter(); Utility.ClearCookie(filter, chat_uri); HttpCookieManager cookieManager = filter.CookieManager; try { foreach (var ck in StaticResources.SelectedShopLogin.lstLoginCookie) { HttpCookie cookie = new HttpCookie(ck.name, ck.domain[0].Equals('.') ? ck.domain : "." + ck.domain, ck.path); cookie.Value = ck.value; cookieManager.SetCookie(cookie, false); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } new Thread(async() => { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { s.Navigate(chat_uri); }); }).Start(); } }); }
public async Task <bool> LoginWithFacebook() { //Get all the cookies from storage StorageFolder temp = ApplicationData.Current.LocalFolder; //Check if it might be there IReadOnlyList <IStorageItem> tempItems = await temp.GetItemsAsync(); if (tempItems.Count > 0) { StorageFile fil = await temp.GetFileAsync("cookie"); //Convert string text = await Windows.Storage.FileIO.ReadTextAsync(fil); List <HttpCookie> cooklist = JsonConvert.DeserializeObject <List <HttpCookie> >(text.ToString()); //Apply them to the httpclient, so we can log in. foreach (HttpCookie cook in cooklist) { cookieMonster.SetCookie(cook); } //Check if it works Response resp = await getResponse("http://followshows.com/", null); if (resp.page == null || !resp.content.IsSuccessStatusCode || resp.page.Contains("Wrong email or password.") || resp.page.Contains("Already have an account? Log in now")) { return(false); } //Pure hapiness return(true); } return(false); }
public async Task <bool> LoginWithFacebook() { //Get all the cookies from storage StorageFolder temp = ApplicationData.Current.LocalFolder; //Check if it might be there IReadOnlyList <IStorageItem> tempItems = await temp.GetItemsAsync(); if (tempItems.Count > 0) { StorageFile fil = await temp.GetFileAsync("cookie"); //Convert string text = await Windows.Storage.FileIO.ReadTextAsync(fil); List <HttpCookie> cooklist = JsonConvert.DeserializeObject <List <HttpCookie> >(text.ToString()); //Apply them to the httpclient, so we can log in. foreach (HttpCookie cook in cooklist) { cookieMonster.SetCookie(cook); } //Check if it works Response resp = await(new Response("http://followshows.com/")).call(); if (resp.somethingWentWrong) { return(false); } //Pure hapiness return(true); } return(false); }
/// <summary> /// Login into LNU, should only call it when login-cookie is gone. /// </summary> /// <param name="client"></param> /// <param name="user"></param> /// <param name="password"></param> /// <returns></returns> public static async Task <LoginReturnBag> PostLNULoginCallback(HttpClient client, string user, string password) { /// Changes for Windows Store //var urlString = string.Format("http://jwgl.lnu.edu.cn/pls/wwwbks/bks_login2.login?stuid={0}&pwd={1}", user, password); var urlString = string.Format("https://notificationhubforuwp.azurewebsites.net/LNU/Redirect?user={0}&psw={1}", user, password); var bag = new LoginReturnBag(); try { // do not dispose, so that the global undirect httpclient will stay in referenced. dispose it when you need. var httpClient = client; //httpClient.DefaultRequestHeaders.Host = new Windows.Networking.HostName("jwgl.lnu.edu.cn"); //httpClient.DefaultRequestHeaders.Referer = new Uri("http://jwgl.lnu.edu.cn/zhxt_bks/xk_login.html"); /// using (var response = await LOGIN_POST(client, urlString)) { var returnCookies = UnRedirectCookiesManager.GetCookies(new Uri("https://notificationhubforuwp.azurewebsites.net/")); if (returnCookies.Count == 0) { throw new AccessUnPassedException("Login Failed: no login-success cookie received."); } /// Changes for Windows Store string content = default(string); var value = response.Headers.TryGetValue("Set-Cookie", out content); if (value) { content = content.Split(',')[0].Replace(";", "@").Split('@')[0].Replace("=", "@").Split('@')[1]; HttpCookie cookie = new HttpCookie("ACCOUNT", "jwgl.lnu.edu.cn", "/pls/wwwbks/"); cookie.Value = content; /// DEBUG Method Debug.WriteLine("DEBUG -----> " + content); /// UnRedirectCookiesManager.SetCookie(cookie); bag.CookieBag = cookie; } /// using (var request = GET(client, "http://jwgl.lnu.edu.cn/pls/wwwbks/bks_login2.loginmessage")) { request.Headers.Host = new Windows.Networking.HostName("jwgl.lnu.edu.cn"); request.Headers.Referer = new Uri("http://jwgl.lnu.edu.cn/zhxt_bks/xk_login.html"); var result = await httpClient.SendRequestAsync(request); bag.HtmlResouces = (await CastStreamContentToString(result)).ToString(); } } } catch (ObjectDisposedException ex) { // when web connect recovery , recreate a new instance to implemente a recursive function to solve the problem. Debug.WriteLine("\nFailed:\n" + ex.StackTrace); unRedirectHttpClient = null; return(await PostLNULoginCallback(UnRedirectHttpClient, user, password)); } catch (COMException ex) { // it is obvious that the internrt connect go wrong. Debug.WriteLine("\nFailed:\n" + ex.StackTrace); return(null); } catch (AccessUnPassedException ex) { Debug.WriteLine("\nFailed:\n" + ex.StackTrace); unRedirectHttpClient = null; return(bag); } catch (Exception ex) { // unkown error, report it. Debug.WriteLine("\nFailed:\n" + ex.StackTrace); return(null); } return(bag); }