2023-04-13 11:51:03 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using Aitex.Common.Util;
|
|
|
|
|
using Aitex.Core.RT.Event;
|
|
|
|
|
using Aitex.Core.RT.Key;
|
|
|
|
|
using Aitex.Core.RT.Log;
|
|
|
|
|
using Aitex.Core.Util;
|
|
|
|
|
using MECF.Framework.Common.Account;
|
|
|
|
|
using MECF.Framework.Common.Account.Extends;
|
|
|
|
|
|
|
|
|
|
namespace Aitex.Core.Account
|
|
|
|
|
{
|
|
|
|
|
public sealed class AccountService : IAccountService
|
|
|
|
|
{
|
|
|
|
|
public string Module = "System";
|
|
|
|
|
|
|
|
|
|
public LoginResult Login(string accountId, string accountPwd)
|
|
|
|
|
{
|
|
|
|
|
if (Singleton<KeyManager>.Instance.IsExpired)
|
|
|
|
|
{
|
|
|
|
|
EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not login");
|
|
|
|
|
return new LoginResult
|
|
|
|
|
{
|
|
|
|
|
ActSucc = false,
|
|
|
|
|
Description = "Software is expired"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
EV.PostInfoLog(Module, $"User {accountId} try to login System.");
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.Login(accountId, accountPwd);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Logout(string accountId)
|
|
|
|
|
{
|
|
|
|
|
EV.PostInfoLog(Module, $"User {accountId} logout sytem.");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-08-28 10:30:53 +08:00
|
|
|
|
AccountManager.Instance.Logout(accountId);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GetAccountInfoResult GetAccountInfo(string accountId)
|
|
|
|
|
{
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.GetAccountInfo(accountId);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RegisterViews(List<string> views)
|
|
|
|
|
{
|
2023-08-28 10:30:53 +08:00
|
|
|
|
AccountManager.Instance.RegisterViews(views);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ChangePwdResult ChangePassword(string accountId, string newPassword)
|
|
|
|
|
{
|
|
|
|
|
if (Singleton<KeyManager>.Instance.IsExpired)
|
|
|
|
|
{
|
|
|
|
|
EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
|
|
|
|
|
return new ChangePwdResult();
|
|
|
|
|
}
|
|
|
|
|
EV.PostInfoLog(Module, $"Change user {accountId} password.");
|
|
|
|
|
LOG.Write($"Account operation, change user {accountId} password.");
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.ChangePassword(accountId, newPassword);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CreateAccountResult CreateAccount(Account newAccount)
|
|
|
|
|
{
|
|
|
|
|
if (Singleton<KeyManager>.Instance.IsExpired)
|
|
|
|
|
{
|
|
|
|
|
EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
|
|
|
|
|
return new CreateAccountResult();
|
|
|
|
|
}
|
|
|
|
|
EV.PostInfoLog(Module, $"Create account{newAccount}.");
|
|
|
|
|
LOG.Write($"Account operation, Create user {newAccount.AccountId}.");
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.CreateAccount(newAccount);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DeleteAccountResult DeleteAccount(string accountId)
|
|
|
|
|
{
|
|
|
|
|
if (Singleton<KeyManager>.Instance.IsExpired)
|
|
|
|
|
{
|
|
|
|
|
EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
|
|
|
|
|
return new DeleteAccountResult();
|
|
|
|
|
}
|
|
|
|
|
EV.PostInfoLog(Module, $"Delete account {accountId}.");
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.DeleteAccount(accountId);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UpdateAccountResult UpdateAccount(Account account)
|
|
|
|
|
{
|
|
|
|
|
if (Singleton<KeyManager>.Instance.IsExpired)
|
|
|
|
|
{
|
|
|
|
|
EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
|
|
|
|
|
return new UpdateAccountResult();
|
|
|
|
|
}
|
|
|
|
|
EV.PostInfoLog(Module, $"Update {account} account information.");
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.UpdateAccount(account);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GetAccountListResult GetAccountList()
|
|
|
|
|
{
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.GetAccountList();
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Account> GetLoginUsers()
|
|
|
|
|
{
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.GetLoginUserList();
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void KickUserOut(string accountId, string kickoutReason)
|
|
|
|
|
{
|
|
|
|
|
EV.PostInfoLog(Module, $"Force user {accountId} logout system,reason:{kickoutReason}.");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-08-28 10:30:53 +08:00
|
|
|
|
AccountManager.Instance.Kickout(accountId, kickoutReason);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SerializableDictionary<string, SerializableDictionary<string, ViewPermission>> GetAllRolesPermission()
|
|
|
|
|
{
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.GetAllRolesPermission();
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SaveAllRolesPermission(Dictionary<string, Dictionary<string, ViewPermission>> data)
|
|
|
|
|
{
|
|
|
|
|
if (Singleton<KeyManager>.Instance.IsExpired)
|
|
|
|
|
{
|
|
|
|
|
EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.SaveAllRolesPermission(data);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SerializableDictionary<string, string> GetAllViewList()
|
|
|
|
|
{
|
|
|
|
|
return AccountManager.GetAllViewList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<string> GetAllRoles()
|
|
|
|
|
{
|
2023-08-28 10:30:53 +08:00
|
|
|
|
return AccountManager.Instance.GetAllRoles();
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CheckAlive(string accountId)
|
|
|
|
|
{
|
2023-08-28 10:30:53 +08:00
|
|
|
|
AccountManager.Instance.CheckAlive(accountId);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetProcessViewPermission()
|
|
|
|
|
{
|
|
|
|
|
string filename = Path.Combine(PathManager.GetCfgDir(), "RolePermission.xml");
|
|
|
|
|
XmlDocument xmlDocument = new XmlDocument();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
xmlDocument.Load(filename);
|
|
|
|
|
return xmlDocument.InnerXml;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LOG.Write(ex);
|
|
|
|
|
return "<Aitex></Aitex>";
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SaveProcessViewPermission(string viewXML)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string filename = Path.Combine(PathManager.GetCfgDir(), "RolePermission.xml");
|
|
|
|
|
XmlDocument xmlDocument = new XmlDocument();
|
|
|
|
|
xmlDocument.LoadXml(viewXML);
|
|
|
|
|
XmlTextWriter xmlTextWriter = new XmlTextWriter(filename, null);
|
|
|
|
|
xmlTextWriter.Formatting = Formatting.Indented;
|
|
|
|
|
xmlDocument.Save(xmlTextWriter);
|
|
|
|
|
xmlTextWriter.Close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LOG.Write(ex);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Role> GetAllRoleList()
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.RoleList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<AccountEx> GetAllAccountExList()
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.AccountList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Role> GetRoles()
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.GetRoles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<AccountEx> GetAccounts()
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.GetAccounts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool UpdateRole(Role role)
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.UpdateRole(role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeleteRole(string roleId)
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.DeleteRole(roleId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<AppMenu> GetMenusByRole(string roleId, List<AppMenu> lstMenu)
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.GetMenusByRole(roleId, lstMenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetMenuPermission(string roleId, string menuName)
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.GetMenuPermission(roleId, menuName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool UpdateAccountEx(AccountEx account)
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.UpdateAccount(account);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeleteAccountEx(string accountId)
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.RoleLoader.DeleteAccount(accountId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LoginResult LoginEx(string accountId, string password, string role)
|
|
|
|
|
{
|
|
|
|
|
return Singleton<AccountExManager>.Instance.AuthLogin(accountId, password, role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LogoutEx(string accountId, string loginId)
|
|
|
|
|
{
|
|
|
|
|
Singleton<AccountExManager>.Instance.Logout(accountId, loginId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|