Exemple #1
0
        public bool Authenticate()
        {
            ExpireCookies();
            Cookies.SetCookies(_httpHotelUri, SKore.GetIpCookie(Hotel));
            try
            {
                byte[] postData     = Encoding.UTF8.GetBytes(string.Format("{{\"email\":\"{0}\",\"password\":\"{1}\"}}", Email, Password));
                var    loginRequest = (HttpWebRequest)WebRequest.Create(string.Format("{0}/api/public/authentication/login", _httpsHotelUri.OriginalString));
                loginRequest.ContentType       = "application/json;charset=UTF-8";
                loginRequest.UserAgent         = SKore.ChromeAgent;
                loginRequest.AllowAutoRedirect = false;
                loginRequest.CookieContainer   = Cookies;
                loginRequest.Method            = "POST";
                loginRequest.Proxy             = null;

                using (Stream requestStream = loginRequest.GetRequestStream())
                    requestStream.Write(postData, 0, postData.Length);

                using (var response = (HttpWebResponse)loginRequest.GetResponse())
                    using (var streamReader = new StreamReader(response.GetResponseStream()))
                    {
                        Cookies.Add(response.Cookies);
                        string responseBody = streamReader.ReadToEnd();
                        UpdateSession(responseBody);
                    }
                return(true);
            }
            catch { return(false); }
        }
Exemple #2
0
        public bool Login()
        {
            Dispose();
            Cookies.SetCookies(new Uri(Hotel.ToUrl()), SKore.GetIpCookie());

            try
            {
                #region Authentication
                byte[] postData = Encoding.Default.GetBytes(string.Format("credentials.username={0}&credentials.password={1}", Email, Password));
                var    request  = (HttpWebRequest)WebRequest.Create(string.Format("{0}/account/submit", Hotel.ToUrl(true)));
                request.ContentType       = "application/x-www-form-urlencoded";
                request.UserAgent         = SKore.ChromeAgent;
                request.AllowAutoRedirect = false;
                request.CookieContainer   = Cookies;
                request.Method            = "POST";
                request.Proxy             = null;

                using (Stream dataStream = request.GetRequestStream())
                    dataStream.Write(postData, 0, postData.Length);

                string body;
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    Cookies.Add(response.Cookies);
                    using (var streamReader = new StreamReader(response.GetResponseStream()))
                        body = streamReader.ReadToEnd();
                }
                #endregion

                if (body.Contains("useOrCreateAvatar"))
                {
                    #region Player Selection
                    PlayerId                  = int.Parse(body.GetChild("useOrCreateAvatar/", '?'));
                    request                   = (HttpWebRequest)WebRequest.Create(string.Format("{0}/identity/useOrCreateAvatar/{1}?next=", Hotel.ToUrl(), PlayerId));
                    request.UserAgent         = SKore.ChromeAgent;
                    request.CookieContainer   = Cookies;
                    request.AllowAutoRedirect = false;
                    request.Method            = "GET";

                    string redirectingTo;
                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        Cookies.Add(response.Cookies);
                        redirectingTo = response.Headers["Location"];
                    }
                    #endregion

                    #region Manual Redirect
                    request                   = (HttpWebRequest)WebRequest.Create(redirectingTo);
                    request.UserAgent         = SKore.ChromeAgent;
                    request.CookieContainer   = Cookies;
                    request.AllowAutoRedirect = false;
                    request.Method            = "GET";

                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        Cookies.Add(response.Cookies);

                        using (var streamReader = new StreamReader(response.GetResponseStream()))
                            body = streamReader.ReadToEnd();

                        if (redirectingTo.EndsWith("/me"))
                        {
                            HandleResource(HPage.Me, ref body);
                            return(true);
                        }
                    }
                    #endregion

                    if (body.Contains("/account/updateIdentityProfileTerms"))
                    {
                        #region Accept Terms Of Service
                        postData                  = Encoding.Default.GetBytes("termsSelection=true");
                        request                   = (HttpWebRequest)WebRequest.Create(string.Format("{0}/account/updateIdentityProfileTerms", Hotel.ToUrl(true)));
                        request.ContentType       = "application/x-www-form-urlencoded";
                        request.Headers["Origin"] = Hotel.ToUrl(true);
                        request.UserAgent         = SKore.ChromeAgent;
                        request.AllowAutoRedirect = false;
                        request.CookieContainer   = Cookies;
                        request.Referer           = redirectingTo;
                        request.Method            = "POST";

                        using (Stream dataStream = request.GetRequestStream())
                            dataStream.Write(postData, 0, postData.Length);

                        using (var response = (HttpWebResponse)request.GetResponse())
                            Cookies.Add(response.Cookies);
                        #endregion
                    }
                    else if (body.Contains("/account/updateIdentityProfileEmail"))
                    {
                        #region Skip Email Verification
                        postData                  = Encoding.Default.GetBytes("email=&skipEmailChange=true");
                        request                   = (HttpWebRequest)WebRequest.Create(string.Format("{0}/account/updateIdentityProfileEmail", Hotel.ToUrl(true)));
                        request.ContentType       = "application/x-www-form-urlencoded";
                        request.Headers["Origin"] = Hotel.ToUrl(true);
                        request.UserAgent         = SKore.ChromeAgent;
                        request.AllowAutoRedirect = false;
                        request.CookieContainer   = Cookies;
                        request.Referer           = redirectingTo;
                        request.Method            = "POST";

                        using (Stream dataStream = request.GetRequestStream())
                            dataStream.Write(postData, 0, postData.Length);

                        using (var response = (HttpWebResponse)request.GetResponse())
                            Cookies.Add(response.Cookies);
                        #endregion
                    }

                    if (body.Contains("/account/updateIdentityProfileTerms") || body.Contains("/account/updateIdentityProfileEmail"))
                    {
                        #region Player Selection
                        request                   = (HttpWebRequest)WebRequest.Create(string.Format("{0}/identity/useOrCreateAvatar/{1}?disableFriendLinking=false&combineIdentitiesSelection=2&next=&selectedAvatarId=", Hotel.ToUrl(), PlayerId));
                        request.UserAgent         = SKore.ChromeAgent;
                        request.CookieContainer   = Cookies;
                        request.AllowAutoRedirect = false;
                        request.Method            = "GET";

                        using (var response = (HttpWebResponse)request.GetResponse())
                        {
                            Cookies.Add(response.Cookies);
                            redirectingTo = response.Headers["Location"];
                        }
                        #endregion

                        #region Manual Redirect
                        request                   = (HttpWebRequest)WebRequest.Create(redirectingTo);
                        request.UserAgent         = SKore.ChromeAgent;
                        request.CookieContainer   = Cookies;
                        request.AllowAutoRedirect = false;
                        request.Method            = "GET";

                        using (var response = (HttpWebResponse)request.GetResponse())
                        {
                            Cookies.Add(response.Cookies);

                            using (var streamReader = new StreamReader(response.GetResponseStream()))
                                body = streamReader.ReadToEnd();

                            if (redirectingTo.EndsWith("/me"))
                            {
                                HandleResource(HPage.Me, ref body);
                                return(true);
                            }
                        }
                        #endregion
                    }
                }
            }
            catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
            return(false);
        }