提交rbac
提交设置右键错位的bug
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
using AntdUI;
|
||||
using DH.RBAC.Logic.Sys;
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Utility.Other;
|
||||
using DHSoftware.Models;
|
||||
using DHSoftware.Services;
|
||||
|
||||
@ -6,9 +9,15 @@ namespace DHSoftware
|
||||
{
|
||||
public partial class LoginWindow : AntdUI.Window
|
||||
{
|
||||
private SysUserLogic userlogic;
|
||||
private SysUserLogOnLogic userLogOnLogic;
|
||||
private SysPermissionLogic permissionLogic;
|
||||
public LoginWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
userlogic = new SysUserLogic();
|
||||
userLogOnLogic = new SysUserLogOnLogic();
|
||||
permissionLogic = new SysPermissionLogic();
|
||||
// 关键设置:允许窗体优先接收按键事件
|
||||
this.KeyPreview = true;
|
||||
|
||||
@ -18,6 +27,7 @@ namespace DHSoftware
|
||||
button_cancel.Click += Button_cancel_Click;
|
||||
}
|
||||
|
||||
|
||||
private void Login_KeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
// 监听回车键
|
||||
@ -40,7 +50,7 @@ namespace DHSoftware
|
||||
/// </summary>
|
||||
private static LoginWindow _instance;
|
||||
|
||||
internal static LoginWindow Instance
|
||||
public static LoginWindow Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -50,74 +60,79 @@ namespace DHSoftware
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindow parentForm;
|
||||
private void Button_cancel_Click(object? sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
private void Button_ok_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(iptName.Text))
|
||||
string userName = iptName.Text;
|
||||
string password = iptPwd.Text;
|
||||
if (StringHelper.IsNullOrEmpty(userName))
|
||||
{
|
||||
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;
|
||||
}
|
||||
AntdUI.Message.warn(this, "请输入用户名!", autoClose: 3);
|
||||
|
||||
parent.LoginName = iptName.Text;
|
||||
}
|
||||
this.Dispose();
|
||||
return;
|
||||
}
|
||||
if (StringHelper.IsNullOrEmpty(password))
|
||||
{
|
||||
AntdUI.Message.warn(this, "请输入密码!", autoClose: 3);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
password = password.MD5Encrypt();
|
||||
var userEntity = userlogic.GetByUserName(userName);
|
||||
if (userEntity == null)
|
||||
{
|
||||
AntdUI.Message.warn(this, "该账户不存在,请重新输入!", autoClose: 3);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
if (!userEntity.IsEnabled)
|
||||
{
|
||||
AntdUI.Message.warn(this, "该账户已被禁用,请联系管理员!", autoClose: 3);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
var userLogOnEntity = userLogOnLogic.GetByAccount(userEntity.Id);
|
||||
string inputPassword = password.DESEncrypt(userLogOnEntity.SecretKey).MD5Encrypt();
|
||||
if (inputPassword != userLogOnEntity.Password)
|
||||
{
|
||||
AntdUI.Message.warn(this, "密码错误,请重新输入!", autoClose: 3);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
userLogOnLogic.UpdateLogin(userLogOnEntity);
|
||||
|
||||
DH.RBAC.Common.GlobalConfig.CurrentUser = userEntity;
|
||||
List<SysPermission> list;
|
||||
if (userlogic.ContainsUser("admin", DH.RBAC.Common.GlobalConfig.CurrentUser.Id))
|
||||
{
|
||||
list = permissionLogic.GetList();
|
||||
}
|
||||
else
|
||||
{
|
||||
AntdUI.Message.warn(this, "用户名或密码错误,登录失败!", autoClose: 3);
|
||||
list = permissionLogic.GetList(DH.RBAC.Common.GlobalConfig.CurrentUser.Id);
|
||||
}
|
||||
if (list.IsNullOrEmpty())
|
||||
{
|
||||
AntdUI.Message.warn(this, "网络或服务器异常,请稍后重试!", autoClose: 3);
|
||||
|
||||
return;
|
||||
}
|
||||
DH.RBAC.Common.GlobalConfig.PermissionList = list;
|
||||
DialogResult = DialogResult.OK;
|
||||
parentForm.ButtonPermissionList = DH.RBAC.Common.GlobalConfig.PermissionList.ToList();
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
private void LoginWindow_Load(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user