示例#1
0
        public async Task <bool> LoginAsync()
        {
            try
            {
                IsAuthenticated = false;
                byte[] postData = Encoding.UTF8.GetBytes(
                    $"{{\"email\":\"{Email}\",\"password\":\"{Password}\"}}");

                var request = (HttpWebRequest)WebRequest.Create(
                    _hotelUri.OriginalString + "/api/public/authentication/login");

                request.ContentType = "application/json;charset=UTF-8";
                string body = await Requester.DownloadStringAsync(
                    request, postData).ConfigureAwait(false);

                if (!string.IsNullOrWhiteSpace(body) &&
                    !body.Equals("{\"message\":\"invalid-captcha\",\"captcha\":true}"))
                {
                    IsAuthenticated = true;
                    User            = HUser.Create(body);
                }
            }
            catch { IsAuthenticated = false; }
            return(IsAuthenticated);
        }
示例#2
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);
                    }
        }
示例#3
0
 public static async Task <HUser> GetUserAsync(string name, HHotel hotel) => HUser.Create(await ReadContentAsync <string>(hotel.ToUri(), ("/api/public/users?name=" + name)));