예제 #1
0
        private void Back_Click(object sender, RoutedEventArgs e)
        {
            AdministratorPanel administratorPanel = new AdministratorPanel();

            administratorPanel.Show();

            this.Close();
        }
예제 #2
0
        private async void loginButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(StringContainer.port))
                {
                    StringContainer.port = this.Port.Text;
                    var sc = new StringContainer(this.Port.Text);
                }

                var json    = JsonConvert.SerializeObject(new AuthModel(this.login.Text, this.password.Password));
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage responseMessage = await client.PostAsync(StringContainer.Authorization, content);

                string responseBody = await responseMessage.Content.ReadAsStringAsync();

                var response = JsonConvert.DeserializeObject <LoggedUser>(responseBody);

                if (!responseMessage.IsSuccessStatusCode)
                {
                    throw new ExceptionModel(response.details[0]);
                }

                LoggedUserHelper.loggedUser = response;
                ClientHelper.SetHeaders(response.tokenType, response.accessToken);

                if (response.roles[0] == "ROLE_ADMIN")
                {
                    AdministratorPanel administratorPanel = new AdministratorPanel();
                    administratorPanel.Show();

                    this.Close();
                }
                else
                {
                    MainWindow window = new MainWindow();
                    window.Show();

                    this.Close();
                }
            }
            catch (ExceptionModel ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }