| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using DeviceCenter.model;
- using DeviceCenter.utils;
- using System;
- using System.Collections.Generic;
- using System.Windows;
- namespace DeviceCenter
- {
- /// <summary>
- /// Login.xaml 的交互逻辑
- /// </summary>
- public partial class Login : Window
- {
- private Config config = Config.getInstance();
- public Login()
- {
- InitializeComponent();
- this.MouseDown += delegate { DragMove(); };
- if (!string.IsNullOrEmpty(config.url))
- {
- tb_server_url.Text = config.url;
- }
- if (!string.IsNullOrEmpty(config.url))
- {
- tb_username.Text = config.username;
- }
- if (!string.IsNullOrEmpty(config.url))
- {
- tb_passowrd.Password = config.password;
- }
- }
- private void btn_login_Click(object sender, RoutedEventArgs e)
- {
- if (string.IsNullOrWhiteSpace(tb_server_url.Text))
- {
- MessageBox.Show("请输入服务器地址");
- return;
- }
- if (string.IsNullOrWhiteSpace(tb_username.Text))
- {
- MessageBox.Show("请输入用户名");
- return;
- }
- if (string.IsNullOrWhiteSpace(tb_passowrd.Password))
- {
- MessageBox.Show("请输入密码");
- return;
- }
- btns.Visibility = Visibility.Collapsed;
- loading.Visibility = Visibility.Visible;
- login();
- }
- private void btn_quit_Click(object sender, RoutedEventArgs e)
- {
- Environment.Exit(0);
- }
- async void login()
- {
- config.username = tb_username.Text;
- config.password = tb_passowrd.Password;
- config.url = tb_server_url.Text;
- config.save();
- http.post<string>("auth/login", new Dictionary<string, string>
- {
- ["username"] = tb_username.Text,
- ["password"] = tb_passowrd.Password
- })
- .Then(token =>
- {
- config.token = token;
- MainWindow mainWindow = new MainWindow();
- mainWindow.Show();
- Close();
- })
- .Catch(e =>
- {
- btns.Visibility = Visibility.Visible;
- loading.Visibility = Visibility.Collapsed;
- MessageBox.Show(e.Message);
- });
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- if (!string.IsNullOrWhiteSpace(config.username) && !string.IsNullOrWhiteSpace(config.password))
- {
- btn_login_Click(null, null);
- }
- }
- }
- }
|