95 lines
2.7 KiB
C#
95 lines
2.7 KiB
C#
using AntdUI;
|
|
using DHSoftware.Models;
|
|
using DHSoftware.Services;
|
|
namespace DHSoftware
|
|
{
|
|
|
|
|
|
|
|
public partial class LoginWindow : AntdUI.Window
|
|
{
|
|
|
|
public LoginWindow()
|
|
{
|
|
|
|
InitializeComponent();
|
|
button_ok.Click += Button_ok_Click;
|
|
button_cancel.Click += Button_cancel_Click;
|
|
|
|
}
|
|
|
|
private void Button_cancel_Click(object? sender, EventArgs e)
|
|
{
|
|
this.Dispose();
|
|
}
|
|
|
|
private void Button_ok_Click(object? sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(iptName.Text))
|
|
{
|
|
AntdUI.Message.warn(this, "用户名不能为空!", autoClose: 3);
|
|
return;
|
|
}
|
|
if (string.IsNullOrWhiteSpace(iptPwd.Text))
|
|
{
|
|
AntdUI.Message.warn(this, "密码不能为空!", autoClose: 3);
|
|
return;
|
|
}
|
|
if(AuthService.Login(iptName.Text, iptPwd.Text))
|
|
{
|
|
|
|
if (this.Owner is MainWindow parent)
|
|
{
|
|
List<string> UserPermissions = AuthService.GetUserPermissions();
|
|
// 检查当前用户是否有权限
|
|
if (AuthService.HasPermission("system:config"))
|
|
{
|
|
parent.ShowConfig = true;
|
|
}
|
|
else
|
|
{
|
|
parent.ShowConfig = false;
|
|
}
|
|
if (AuthService.HasPermission("system:loadscheme"))
|
|
{
|
|
parent.Loadscheme = true;
|
|
}
|
|
else
|
|
{
|
|
parent.Loadscheme = false;
|
|
}
|
|
if (AuthService.HasPermission("system:addscheme"))
|
|
{
|
|
parent.Addscheme = true;
|
|
}
|
|
else
|
|
{
|
|
parent.Addscheme = false;
|
|
}
|
|
if (AuthService.HasPermission("system:deletescheme"))
|
|
{
|
|
parent.Deleteschememe = true;
|
|
}
|
|
else
|
|
{
|
|
parent.Deleteschememe = false;
|
|
}
|
|
|
|
|
|
parent.LoginName=iptName.Text;
|
|
}
|
|
this.Dispose();
|
|
}
|
|
else
|
|
{
|
|
AntdUI.Message.warn(this, "用户名或密码错误,登录失败!", autoClose: 3);
|
|
}
|
|
}
|
|
|
|
private void LoginWindow_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|