Esempio n. 1
0
        //Utils
        static void cleanCookies()
        {
            //Remove cookies before anything
            Windows.Web.Http.Filters.HttpBaseProtocolFilter myFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
            var cookieManager = myFilter.CookieManager;

            Windows.Web.Http.HttpCookieCollection myCookieJar = cookieManager.GetCookies(new Uri("http://forum.hardware.fr"));
            foreach (Windows.Web.Http.HttpCookie cookie in myCookieJar)
            {
                cookieManager.DeleteCookie(cookie);
            }
            //--
        }
        public async static void ClearCookies(LoginOptions loginOptions)
        {
            Frame frame = Window.Current.Content as Frame;

            if (frame != null)
            {
                await frame.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Uri loginUri = new Uri(ComputeAuthorizationUrl(loginOptions));
                    WebView web  = new WebView();
                    Windows.Web.Http.Filters.HttpBaseProtocolFilter myFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
                    var cookieManager = myFilter.CookieManager;
                    Windows.Web.Http.HttpCookieCollection cookies = cookieManager.GetCookies(loginUri);
                    foreach (Windows.Web.Http.HttpCookie cookie in cookies)
                    {
                        cookieManager.DeleteCookie(cookie);
                    }
                });
            }
        }
Esempio n. 3
0
        public static Task <bool> BeginAuthentication(this Account account, bool firstConnection)
        {
            Debug.WriteLine("Begin connection");
            var tcs = new TaskCompletionSource <bool>();

            //Remove cookies before anything
            Windows.Web.Http.Filters.HttpBaseProtocolFilter myFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
            var cookieManager = myFilter.CookieManager;

            Windows.Web.Http.HttpCookieCollection myCookieJar = cookieManager.GetCookies(new Uri("http://forum.hardware.fr"));
            foreach (Windows.Web.Http.HttpCookie cookie in myCookieJar)
            {
                cookieManager.DeleteCookie(cookie);
            }
            //--

            var pseudo          = account.Pseudo;
            var pseudoEncoded   = WebUtility.UrlEncode(pseudo);
            var password        = account.Password;
            var cookieContainer = new CookieContainer();

#warning "this must be rewritten using HttpClientHelper"

            var request = WebRequest.CreateHttp(HFRUrl.ForumUrl + HFRUrl.ConnectUrl);
            request.ContentType     = "application/x-www-form-urlencoded";
            request.Method          = "POST";
            request.CookieContainer = cookieContainer;
            request.BeginGetRequestStream(ar =>
            {
                try
                {
                    var postStream = request.EndGetRequestStream(ar);
                    var postData   = "&pseudo=" + pseudoEncoded + "&password="******"cookieCount :" + cookieContainer.Count);

                        switch (cookieContainer.Count)
                        {
                        case 0:
                                #warning "no UI feedback to warn user that something went wrong"
                            tcs.SetResult(false);
                            break;

                        case 3:
                            Debug.WriteLine("Connection succeed");
                            account.CookieContainer = JsonConvert.SerializeObject(cookieContainer.GetCookies(new Uri("http://forum.hardware.fr")).OfType <Cookie>().ToList());

                            if (firstConnection)
                            {
                                await GetAvatar(account);
                            }
                            tcs.SetResult(true);
                            break;
                        }
                    }, request);
                }
                catch (WebException exception)
                {
                    Debug.WriteLine("Failed to connect. WebException error");
                    tcs.SetResult(false);
                }
            }, request);
            return(tcs.Task);
        }