Example #1
0
        public async Task <bool> LoginAsync()
        {
            IsAuthenticated = false;
            Cookies.SetCookies(_hotelUri, await SKore.GetIPCookieAsync(Hotel).ConfigureAwait(false));
            byte[] postData = Encoding.UTF8.GetBytes($"{{\"email\":\"{Email}\",\"password\":\"{Password}\"}}");

            var loginRequest = (HttpWebRequest)WebRequest.Create($"{_hotelUri.OriginalString}/api/public/authentication/login");

            loginRequest.ContentType       = "application/json;charset=UTF-8";
            loginRequest.CookieContainer   = Cookies;
            loginRequest.AllowAutoRedirect = false;
            loginRequest.Method            = "POST";
            loginRequest.Proxy             = null;

            using (Stream requestStream = await loginRequest.GetRequestStreamAsync().ConfigureAwait(false))
                await requestStream.WriteAsync(postData, 0, postData.Length).ConfigureAwait(false);

            using (WebResponse loginResponse = await loginRequest.GetResponseAsync().ConfigureAwait(false))
                using (Stream loginStream = loginResponse.GetResponseStream())
                    using (var loginReader = new StreamReader(loginStream))
                    {
                        string body = await loginReader.ReadToEndAsync().ConfigureAwait(false);

                        User = HUser.Create(body);
                        Cookies.SetCookies(_hotelUri, loginResponse.Headers["Set-Cookie"]);
                        IsAuthenticated = ((HttpWebResponse)loginResponse).StatusCode == HttpStatusCode.OK;

                        if (IsAuthenticated)
                        {
                            await ExtractGameDataAsync().ConfigureAwait(false);
                        }

                        return(IsAuthenticated);
                    }
        }