Ejemplo n.º 1
0
        public LoginViewModel()
        {
            LoginClickCommand = new Command(arg => LoginClick());
            RegisterClickCommand = new Command(arg => RegisterClick());

            TestClickCommand = new Command(arg => TestClick());
            User = new User();
        }
Ejemplo n.º 2
0
        private async void SendButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(loginTextBox.Text) || string.IsNullOrEmpty(pwTextBox.Text))
            {
                MessageBox.Show("Fill all fields");
                return;
            }

            string login = loginTextBox.Text;
            string password = pwTextBox.Text;
            User user = new User
            {
                Username = login, PasswordHash = GetMD5(password)
            };

            using (HttpClient client = new HttpClient())
            {
                string uri = $"{_apiUri}/api/User/register";

                HttpContent content = new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json");
                var response = await client.PostAsync(uri, content);

                if (response.IsSuccessStatusCode)
                {
                    MessageBox.Show($"User {user.Username} Registered Successfully", "Registered");
                }
                else if (response.StatusCode == HttpStatusCode.Conflict)
                {
                    MessageBox.Show("User with this username already created or connection failed!");
                }
                else
                {
                    MessageBox.Show("Some error occured!");
                }
            }
        }
Ejemplo n.º 3
0
        private async void TestClick()
        {
            using (HttpClient client = new HttpClient())
            {
                var user = new User()
                {
                    Username = "******",
                    PasswordHash = "hash2hash",
                    Token = "890"
                };
                var response =
                    client.PostAsync("http://localhost:13790/api/User/PostTest",
                        new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json")).Result;
                if (response.IsSuccessStatusCode)
                {
                    string res = await response.Content.ReadAsStringAsync();
                    User us = JsonConvert.DeserializeObject<User>(res);
                    MessageBox.Show(us.Username);

                    
                }
            }
        }