示例#1
0
        public static async Task <bool> LoginRequest(string username, string password)
        {
            var data = new { username, password };

            // All checks have passed. Request the Level.
            try {
                // Run the Login Request
                Uri uri = new Uri(GameValues.CreoAPI + "login");
                HttpResponseMessage response = await WebHandler.PostJSON(uri, data);

                if (response == null || response.IsSuccessStatusCode == false)
                {
                    return(false);
                }

                // Extract the contents from the response.
                string contents = await response.Content.ReadAsStringAsync();

                LoginFormat json = JsonConvert.DeserializeObject <LoginFormat>(contents);

                if (json.success == false)
                {
                    if (json.reason is string)
                    {
                        WebHandler.ResponseMessage = json.reason;
                    }
                    return(false);
                }
                else
                {
                    WebHandler.ResponseMessage = "";
                }

                // Save Login Cookies
                Dictionary <string, string> cookies = GetCookiesFromResponse(response);
                WebHandler.SaveLoginCookies(cookies);

                // Verify the Cookies Were Sent
                return(WebHandler.IsLoggedIn());
            } catch (Exception ex) {
                return(false);
            }
        }
示例#2
0
        public static async Task <bool> RegisterRequest(string email, string username, string password)
        {
            var data = new { email, username, password };

            // All checks have passed. Request the Level.
            try {
                // Run the Login Request
                Uri uri = new Uri(GameValues.CreoAPI + "register");
                HttpResponseMessage response = await WebHandler.PostJSON(uri, data);

                if (response == null || response.IsSuccessStatusCode == false)
                {
                    WebHandler.ResponseMessage = "No Response was provided.";
                    return(false);
                }

                // Extract the contents from the response.
                string contents = await response.Content.ReadAsStringAsync();

                RegisterFormat json = JsonConvert.DeserializeObject <RegisterFormat>(contents);

                if (json.success == false)
                {
                    if (json.reason is string)
                    {
                        WebHandler.ResponseMessage = json.reason;
                    }
                    return(false);
                }
                else
                {
                    WebHandler.ResponseMessage = "";
                }

                return(true);
            } catch (Exception ex) {
                return(false);
            }
        }