87 lines
2.4 KiB
C#
87 lines
2.4 KiB
C#
using edu.huvtc.utils;
|
|
using System.Diagnostics;
|
|
using System.Xml.Linq;
|
|
|
|
namespace FileProcessClient
|
|
{
|
|
public partial class LoginForm : Form
|
|
{
|
|
public LoginForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private async void btnLogin_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
string username = txtName.Text;
|
|
if (username.Length == 0)
|
|
{
|
|
MessageBox.Show("请输入账号!");
|
|
return;
|
|
}
|
|
string password = txtPassword.Text;
|
|
if (password.Length == 0)
|
|
{
|
|
MessageBox.Show("请输入密码!");
|
|
return;
|
|
}
|
|
|
|
//Trace.WriteLine(password);
|
|
|
|
Trace.WriteLine(username);
|
|
|
|
bool flag = await HttpUtils.validateLogin(username, password);
|
|
if (!flag)
|
|
{
|
|
MessageBox.Show("用户名或密码错误,请重试");
|
|
return;
|
|
}
|
|
|
|
|
|
if (chkSavePassword.Checked)
|
|
{
|
|
CommonUtils.writeToIni("userData", "userName", Convert.ToBase64String(CommonUtils.EncryptString(username)));
|
|
CommonUtils.writeToIni("userData", "password", Convert.ToBase64String(CommonUtils.EncryptString(password)));
|
|
}
|
|
|
|
await HttpUtils.getUserInfo();
|
|
|
|
loadMainForm();
|
|
}
|
|
private void loadMainForm()
|
|
{
|
|
mainForm mainForm = new mainForm();
|
|
mainForm.Show();
|
|
this.Hide();
|
|
}
|
|
private async void LoginForm_Activated(object sender, EventArgs e)
|
|
{
|
|
|
|
bool valid = await HttpUtils.getUserInfo();
|
|
if (!valid)
|
|
{
|
|
string name = CommonUtils.readFromFile("userData", "username");
|
|
//Trace.WriteLine(name);
|
|
if (name != null && name != "")
|
|
{
|
|
txtName.Text = CommonUtils.DecryptToString(Convert.FromBase64String(name));
|
|
}
|
|
|
|
string password = CommonUtils.readFromFile("userData", "password");
|
|
//Trace.WriteLine(name);
|
|
if (password != null && password != "")
|
|
{
|
|
txtPassword.Text = CommonUtils.DecryptToString(Convert.FromBase64String(password));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
loadMainForm();
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|