using JNPF.Common.Configuration; using JNPF.Common.Const; using JNPF.Common.Core.Manager; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Filter; using JNPF.Common.Manager; using JNPF.Common.Security; using JNPF.DataEncryption; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; using JNPF.Systems.Entitys.Dto.Permission.UsersCurrent; using JNPF.Systems.Entitys.Dto.UsersCurrent; using JNPF.Systems.Entitys.Entity.Permission; using JNPF.Systems.Entitys.Model.UsersCurrent; using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Entitys.System; using JNPF.Systems.Interfaces.Permission; using JNPF.Systems.Interfaces.System; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; namespace JNPF.Systems; /// /// 业务实现:个人资料. /// [ApiDescriptionSettings(Tag = "Permission", Name = "Current", Order = 168)] [Route("api/permission/Users/[controller]")] public class UsersCurrentService : IUsersCurrentService, IDynamicApiController, ITransient { /// /// 基础仓储. /// private readonly ISqlSugarRepository _repository; /// /// 操作权限服务. /// private readonly IAuthorizeService _authorizeService; /// /// 组织管理. /// private readonly IOrganizeService _organizeService; /// /// 缓存管理器. /// private readonly ICacheManager _cacheManager; /// /// 系统配置. /// private readonly ISysConfigService _sysConfigService; /// /// 用户管理. /// private readonly IUserManager _userManager; /// /// 操作权限服务. /// private readonly OnlineUserService _onlineUserService; /// /// 初始化一个类型的新实例. /// public UsersCurrentService( ISqlSugarRepository userRepository, IAuthorizeService authorizeService, IOrganizeService organizeService, ICacheManager cacheManager, ISysConfigService sysConfigService, OnlineUserService onlineUserService, IUserManager userManager) { _repository = userRepository; _authorizeService = authorizeService; _organizeService = organizeService; _cacheManager = cacheManager; _sysConfigService = sysConfigService; _onlineUserService = onlineUserService; _userManager = userManager; } #region GET /// /// 获取我的下属. /// /// 用户Id. /// [HttpGet("Subordinate/{id}")] public async Task GetSubordinate(string id) { // 获取用户Id 下属 ,顶级节点为 自己 List? userIds = new List(); if (id == "0") userIds.Add(_userManager.UserId); else userIds = await _repository.AsQueryable().Where(m => m.ManagerId == id && m.DeleteMark == null).Select(m => m.Id).ToListAsync(); if (userIds.Any()) { return await _repository.AsSugarClient().Queryable((a, b, c) => new JoinQueryInfos(JoinType.Left, b.Id == SqlFunc.ToString(a.OrganizeId), JoinType.Left, c.Id == SqlFunc.ToString(a.PositionId))) .WhereIF(userIds.Any(), a => userIds.Contains(a.Id)) .Where(a => a.DeleteMark == null && a.EnabledMark == 1) .OrderBy(a => a.SortCode) .Select((a, b, c) => new UsersCurrentSubordinateOutput { id = a.Id, avatar = SqlFunc.MergeString("/api/File/Image/userAvatar/", a.HeadIcon), userName = SqlFunc.MergeString(a.RealName, "/", a.Account), isLeaf = false, department = b.FullName, position = c.FullName }) .ToListAsync(); } else { return new List(); } } /// /// 获取个人资料. /// /// [HttpGet("BaseInfo")] public async Task GetBaseInfo() { UsersCurrentInfoOutput? data = await _repository.AsSugarClient().Queryable().Where(x => x.Id.Equals(_userManager.UserId)) .Select(a => new UsersCurrentInfoOutput { id = a.Id, account = SqlFunc.IIF(KeyVariable.MultiTenancy == true, SqlFunc.MergeString(_userManager.TenantId, "@", a.Account), a.Account), realName = a.RealName, position = string.Empty, positionId = a.PositionId, organizeId = a.OrganizeId, manager = SqlFunc.Subqueryable().Where(x => x.Id.Equals(a.ManagerId)).Select(x => SqlFunc.MergeString(x.RealName, "/", x.Account)), roleId = string.Empty, roleIds = a.RoleId, creatorTime = a.CreatorTime, prevLogTime = a.PrevLogTime, signature = a.Signature, gender = a.Gender.ToString(), nation = a.Nation, nativePlace = a.NativePlace, entryDate = a.EntryDate, certificatesType = a.CertificatesType, certificatesNumber = a.CertificatesNumber, education = a.Education, birthday = a.Birthday, telePhone = a.TelePhone, landline = a.Landline, mobilePhone = a.MobilePhone, email = a.Email, urgentContacts = a.UrgentContacts, urgentTelePhone = a.UrgentTelePhone, postalAddress = a.PostalAddress, theme = a.Theme, language = a.Language, avatar = SqlFunc.IIF(SqlFunc.IsNullOrEmpty(SqlFunc.ToString(a.HeadIcon)), string.Empty, SqlFunc.MergeString("/api/File/Image/userAvatar/", SqlFunc.ToString(a.HeadIcon))) }).FirstAsync(); // 获取组织树 var orgTree = _organizeService.GetOrgListTreeName(); // 组织结构 data.organize = orgTree.FirstOrDefault(x => x.Id.Equals(data.organizeId))?.Description; // 获取当前用户、当前组织下的所有岗位 List? pNameList = await _repository.AsSugarClient().Queryable((a, b) => new JoinQueryInfos(JoinType.Left, a.Id == b.ObjectId)) .Where((a, b) => b.ObjectType == "Position" && b.UserId == _userManager.UserId && a.OrganizeId == data.organizeId).Select(a => a.FullName).ToListAsync(); data.position = string.Join(",", pNameList); // 获取当前用户、全局角色 和当前组织下的所有角色 List? roleList = await _userManager.GetUserOrgRoleIds(data.roleIds, data.organizeId); data.roleId = await _userManager.GetRoleNameByIds(string.Join(",", roleList)); return data; } /// /// 获取系统权限 . /// /// [HttpGet("Authorize")] public async Task GetAuthorize() { List? roleIds = _userManager.Roles; string? userId = _userManager.UserId; bool isAdmin = _userManager.IsAdministrator; UsersCurrentAuthorizeOutput? output = new UsersCurrentAuthorizeOutput(); List? moduleList = await _authorizeService.GetCurrentUserModuleAuthorize(userId, isAdmin, roleIds.ToArray(), new string[] { _userManager.User.SystemId }); if (moduleList.Any(it => it.Category.Equals("App"))) { moduleList.Where(it => it.Category.Equals("App") && it.ParentId.Equals("-1")).ToList().ForEach(it => { it.ParentId = "1"; }); moduleList.Add(new ModuleEntity() { Id = "1", FullName = "app菜单", Icon = "ym-custom ym-custom-cellphone", ParentId = "-1", Category = "App", Type = 1, SortCode = 99999 }); } List? buttonList = await _authorizeService.GetCurrentUserButtonAuthorize(userId, isAdmin, roleIds.ToArray()); List? columnList = await _authorizeService.GetCurrentUserColumnAuthorize(userId, isAdmin, roleIds.ToArray()); List? resourceList = await _authorizeService.GetCurrentUserResourceAuthorize(userId, isAdmin, roleIds.ToArray()); List? formList = await _authorizeService.GetCurrentUserFormAuthorize(userId, isAdmin, roleIds.ToArray()); if (moduleList.Count != 0) output.module = moduleList.Adapt>().ToTree("-1"); if (buttonList.Count != 0) { List? menuAuthorizeData = new List(); List? pids = buttonList.Select(m => m.ModuleId).ToList(); GetParentsModuleList(pids, moduleList, ref menuAuthorizeData); output.button = menuAuthorizeData.Union(buttonList.Adapt>()).ToList().ToTree("-1"); } if (columnList.Count != 0) { List? menuAuthorizeData = new List(); List? pids = columnList.Select(m => m.ModuleId).ToList(); GetParentsModuleList(pids, moduleList, ref menuAuthorizeData); output.column = menuAuthorizeData.Union(columnList.Adapt>()).ToList().ToTree("-1"); } if (resourceList.Count != 0) { List? resourceData = resourceList.Select(r => new UsersCurrentAuthorizeMoldel { id = r.Id, parentId = r.ModuleId, fullName = r.FullName, icon = "icon-ym icon-ym-extend" }).ToList(); List? menuAuthorizeData = new List(); List? pids = resourceList.Select(bt => bt.ModuleId).ToList(); GetParentsModuleList(pids, moduleList, ref menuAuthorizeData); output.resource = menuAuthorizeData.Union(resourceData.Adapt>()).ToList().ToTree("-1"); } if (formList.Count != 0) { List? formData = formList.Select(r => new UsersCurrentAuthorizeMoldel { id = r.Id, parentId = r.ModuleId, fullName = r.FullName, icon = "icon-ym icon-ym-extend" }).ToList(); List? menuAuthorizeData = new List(); List? pids = formList.Select(bt => bt.ModuleId).ToList(); GetParentsModuleList(pids, moduleList, ref menuAuthorizeData); output.form = menuAuthorizeData.Union(formData.Adapt>()).ToList().ToTree("-1"); } return output; } /// /// 获取系统日志. /// /// 参数. /// [HttpGet("SystemLog")] public async Task GetSystemLog([FromQuery] UsersCurrentSystemLogQuery input) { string? userId = _userManager.UserId; PageInputBase? requestParam = input.Adapt(); var startTime = input.startTime.TimeStampToDateTime(); var endTime = input.endTime.TimeStampToDateTime(); SqlSugarPagedList? data = await _repository.AsSugarClient().Queryable() .WhereIF(!input.startTime.IsNullOrEmpty(), s => s.CreatorTime >= new DateTime(startTime.Year, startTime.Month, startTime.Day, 0, 0, 0, 0)) .WhereIF(!input.endTime.IsNullOrEmpty(), s => s.CreatorTime <= new DateTime(endTime.Year, endTime.Month, endTime.Day, 23, 59, 59, 999)) .WhereIF(!input.keyword.IsNullOrEmpty(), s => s.UserName.Contains(input.keyword) || s.IPAddress.Contains(input.keyword) || s.ModuleName.Contains(input.keyword)) .Where(s => s.Category == input.category && s.UserId == userId).OrderBy(o => o.CreatorTime, OrderByType.Desc) .Select(a => new UsersCurrentSystemLogOutput { creatorTime = a.CreatorTime, userName = a.UserName, ipaddress = a.IPAddress, moduleName = a.ModuleName, category = a.Category, userId = a.UserId, platForm = a.PlatForm, requestURL = a.RequestURL, requestMethod = a.RequestMethod, requestDuration = a.RequestDuration }).ToPagedListAsync(requestParam.currentPage, requestParam.pageSize); return PageResult.SqlSugarPageResult(data); } #endregion #region Post /// /// 修改密码. /// /// [HttpPost("Actions/ModifyPassword")] public async Task ModifyPassword([FromBody] UsersCurrentActionsModifyPasswordInput input) { UserEntity? user = _userManager.User; //if(user.Id.ToLower().Equals("admin")) // admin账号不可修改密码 // throw Oops.Oh(ErrorCode.D5024); if (MD5Encryption.Encrypt(input.oldPassword + user.Secretkey) != user.Password.ToLower()) throw Oops.Oh(ErrorCode.D5007); string? imageCode = await GetCode(input.timestamp); await PwdStrategy(input); if (!input.code.ToLower().Equals(imageCode.ToLower())) { throw Oops.Oh(ErrorCode.D5015); } else { await DelCode(input.timestamp); await DelUserInfo(_userManager.TenantId, user.Id); await _onlineUserService.ForcedOffline(user.Id); } user.Password = MD5Encryption.Encrypt(input.password + user.Secretkey); user.ChangePasswordDate = DateTime.Now; user.LastModifyTime = DateTime.Now; user.LastModifyUserId = _userManager.UserId; int isOk = await _repository.AsUpdateable(user).UpdateColumns(it => new { it.Password, it.ChangePasswordDate, it.LastModifyUserId, it.LastModifyTime }).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw Oops.Oh(ErrorCode.D5008); } /// /// 修改个人资料. /// /// [HttpPut("BaseInfo")] public async Task UpdateBaseInfo([FromBody] UsersCurrentInfoUpInput input) { UserEntity? userInfo = input.Adapt(); userInfo.Id = _userManager.UserId; userInfo.IsAdministrator = Convert.ToInt32(_userManager.IsAdministrator); userInfo.LastModifyTime = DateTime.Now; userInfo.LastModifyUserId = _userManager.UserId; int isOk = await _repository.AsUpdateable(userInfo).UpdateColumns(it => new { it.RealName, it.Signature, it.Gender, it.Nation, it.NativePlace, it.CertificatesType, it.CertificatesNumber, it.Education, it.Birthday, it.TelePhone, it.Landline, it.MobilePhone, it.Email, it.UrgentContacts, it.UrgentTelePhone, it.PostalAddress, it.LastModifyUserId, it.LastModifyTime }).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw Oops.Oh(ErrorCode.D5009); } /// /// 修改主题. /// /// [HttpPut("SystemTheme")] public async Task UpdateBaseInfo([FromBody] UsersCurrentSysTheme input) { UserEntity? user = _userManager.User; user.Theme = input.theme; user.LastModifyTime = DateTime.Now; user.LastModifyUserId = _userManager.UserId; int isOk = await _repository.AsUpdateable(user).UpdateColumns(it => new { it.Theme, it.LastModifyUserId, it.LastModifyTime }).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw Oops.Oh(ErrorCode.D5010); } /// /// 修改语言. /// /// [HttpPut("SystemLanguage")] public async Task UpdateLanguage([FromBody] UsersCurrentSysLanguage input) { UserEntity? user = _userManager.User; user.Language = input.language; user.LastModifyTime = DateTime.Now; user.LastModifyUserId = _userManager.UserId; int isOk = await _repository.AsUpdateable(user).UpdateColumns(it => new { it.Language, it.LastModifyUserId, it.LastModifyTime }).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw Oops.Oh(ErrorCode.D5011); } /// /// 修改头像. /// /// [HttpPut("Avatar/{name}")] public async Task UpdateAvatar(string name) { UserEntity? user = _userManager.User; user.HeadIcon = name; user.LastModifyTime = DateTime.Now; user.LastModifyUserId = _userManager.UserId; int isOk = await _repository.AsUpdateable(user).UpdateColumns(it => new { it.HeadIcon, it.LastModifyUserId, it.LastModifyTime }).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw Oops.Oh(ErrorCode.D5012); } /// /// 切换 默认 : 组织、岗位、系统. /// /// [HttpPut("major")] public async Task DefaultOrganize([FromBody] UsersCurrentDefaultOrganizeInput input) { UserEntity? userInfo = _userManager.User; switch (input.majorType) { case "Organize": // 组织 { userInfo.OrganizeId = input.majorId; List? roleList = await _userManager.GetUserOrgRoleIds(userInfo.RoleId, userInfo.OrganizeId); // 如果该组织下没有角色 则 切换组织失败 if (!roleList.Any()) throw Oops.Oh(ErrorCode.D5023); // 该组织下没有任何权限 则 切换组织失败 if (!_repository.AsSugarClient().Queryable().Where(x => x.ObjectType == "Role" && x.ItemType == "module" && roleList.Contains(x.ObjectId)).Any()) throw Oops.Oh(ErrorCode.D5023); // 获取切换组织 Id 下的所有岗位 List? pList = await _repository.AsSugarClient().Queryable().Where(x => x.OrganizeId == input.majorId).Select(x => x.Id).ToListAsync(); // 获取切换组织的 岗位,如果该组织没有岗位则为空 List? idList = await _repository.AsSugarClient().Queryable() .Where(x => x.UserId == userInfo.Id && pList.Contains(x.ObjectId) && x.ObjectType == "Position").Select(x => x.ObjectId).ToListAsync(); userInfo.PositionId = idList.FirstOrDefault() == null ? string.Empty : idList.FirstOrDefault(); } break; case "Position": // 岗位 userInfo.PositionId = input.majorId; break; case "System": // 系统 if (input.menuType.Equals(1)) { // 系统下没有菜单不允许切换. var mList = await _repository.AsSugarClient().Queryable().Where(x => x.SystemId.Equals(input.majorId) && x.DeleteMark == null && x.Category.Equals("App")).Select(x => x.Id).ToListAsync(); if (!mList.Any()) throw Oops.Oh(ErrorCode.D4009); List? roleList = await _userManager.GetUserOrgRoleIds(userInfo.RoleId, userInfo.OrganizeId); // 非管理员 没有任何权限 切换失败 if (!_userManager.IsAdministrator && !_repository.AsSugarClient().Queryable() .Where(x => x.ObjectType == "Role" && x.ItemType == "module" && roleList.Contains(x.ObjectId)) .Where(x => mList.Contains(x.ItemId)).Any()) throw Oops.Oh(ErrorCode.D5023); userInfo.SystemId = input.majorId; } else { // 当前系统已被管理员禁用. var switchSystem = await _repository.AsSugarClient().Queryable() .Where(it => input.majorId.Equals(it.Id) && it.DeleteMark == null) .FirstAsync(); if (switchSystem != null && !switchSystem.EnabledMark.Equals(1)) throw Oops.Oh(ErrorCode.D4014); // 系统下没有菜单不允许切换. var mList = await _repository.AsSugarClient().Queryable().Where(x => x.SystemId.Equals(input.majorId) && x.DeleteMark == null && x.Category.Equals("Web")).Select(x => x.Id).ToListAsync(); if (!mList.Any()) throw Oops.Oh(ErrorCode.D4009); List? roleList = await _userManager.GetUserOrgRoleIds(userInfo.RoleId, userInfo.OrganizeId); // 非管理员 没有任何权限 切换失败 if (!_userManager.IsAdministrator && !_repository.AsSugarClient().Queryable() .Where(x => x.ObjectType == "Role" && x.ItemType == "module" && roleList.Contains(x.ObjectId)) .Where(x => mList.Contains(x.ItemId)).Any()) throw Oops.Oh(ErrorCode.D5023); userInfo.SystemId = input.majorId; } break; } userInfo.LastModifyTime = DateTime.Now; userInfo.LastModifyUserId = _userManager.UserId; int isOk = await _repository.AsUpdateable(userInfo).UpdateColumns(it => new { it.OrganizeId, it.PositionId, it.LastModifyUserId, it.LastModifyTime, it.SystemId }).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); if (!(isOk > 0)) throw Oops.Oh(ErrorCode.D5020); } /// /// 获取当前用户所有组织. /// /// [HttpGet("getUserOrganizes")] public async Task GetUserOrganizes() { UserEntity? userInfo = _userManager.User; // 获取当前用户所有关联 组织ID 集合 List? idList = await _repository.AsSugarClient().Queryable() .Where(x => x.UserId == userInfo.Id && x.ObjectType == "Organize") .Select(x => x.ObjectId).ToListAsync(); // 获取组织树 var orgTree = _organizeService.GetOrgListTreeName(); // 根据关联组织ID 查询组织信息 List? oList = orgTree.Where(x => idList.Contains(x.Id)) .Select(x => new CurrentUserOrganizesOutput { id = x.Id, fullName = x.Description }).ToList(); CurrentUserOrganizesOutput? def = oList.Where(x => x.id == userInfo.OrganizeId).FirstOrDefault(); if (def != null) def.isDefault = true; return oList; } /// /// 获取当前用户所有岗位. /// /// [HttpGet("getUserPositions")] public async Task GetUserPositions() { UserEntity? userInfo = _userManager.User; // 获取当前用户所有关联 岗位ID 集合 List? idList = await _repository.AsSugarClient().Queryable() .Where(x => x.UserId == userInfo.Id && x.ObjectType == "Position") .Select(x => x.ObjectId).ToListAsync(); // 根据关联 岗位ID 查询岗位信息 List? oList = await _repository.AsSugarClient().Queryable() .Where(x => x.OrganizeId == userInfo.OrganizeId).Where(x => idList.Contains(x.Id)) .Select(x => new CurrentUserOrganizesOutput { id = x.Id, fullName = x.FullName }).ToListAsync(); CurrentUserOrganizesOutput? def = oList.Where(x => x.id == userInfo.PositionId).FirstOrDefault(); if (def != null) def.isDefault = true; return oList; } /// /// 获取当前用户所有签名. /// /// [HttpGet("SignImg")] public async Task GetSignImg() { try { return (await _repository.AsSugarClient().Queryable().Where(x => x.CreatorUserId == _userManager.UserId && x.DeleteMark == null).ToListAsync()).Adapt>(); } catch (Exception ex) { throw; } } /// /// 新增签名. /// /// [HttpPost("SignImg")] public async Task CreateSignImg([FromBody] UsersCurrentSignImgOutput input) { if (!_repository.AsSugarClient().Queryable().Any(x => x.CreatorUserId == _userManager.UserId)) { input.isDefault = 1; } var signImgEntity = input.Adapt(); var entity = await _repository.AsSugarClient().Insertable(signImgEntity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Creator()).ExecuteReturnEntityAsync(); if (entity.IsNullOrEmpty()) throw Oops.Oh(ErrorCode.COM1000); if (input.isDefault == 1) { await _repository.AsSugarClient().Updateable().SetColumns(x => x.IsDefault == 0).Where(x => x.Id != entity.Id && x.CreatorUserId == _userManager.UserId).ExecuteCommandAsync(); } } /// /// 设置默认签名. /// /// [HttpPut("{id}/SignImg")] public async Task UpdateSignImg(string id) { await _repository.AsSugarClient().Updateable().SetColumns(x => x.IsDefault == 0).Where(x => x.Id != id && x.CreatorUserId == _userManager.UserId).ExecuteCommandAsync(); await _repository.AsSugarClient().Updateable().SetColumns(x => x.IsDefault == 1).Where(x => x.Id == id).ExecuteCommandAsync(); } /// /// 删除签名. /// /// [HttpDelete("{id}/SignImg")] public async Task DeleteSignImg(string id) { var isOk = await _repository.AsSugarClient().Updateable().SetColumns(it => new SignImgEntity() { DeleteMark = 1, DeleteUserId = _userManager.UserId, DeleteTime = SqlFunc.GetDate() }).Where(it => it.Id.Equals(id)).ExecuteCommandHasChangeAsync(); if (!isOk) throw Oops.Oh(ErrorCode.COM1003); } #endregion #region PrivateMethod /// /// 过滤菜单权限数据. /// /// 其他权限数据. /// 勾选菜单权限数据. /// 返回值. private void GetParentsModuleList(List pids, List moduleList, ref List output) { List? authorizeModuleData = moduleList.Adapt>(); foreach (string? item in pids) { GteModuleListById(item, authorizeModuleData, output); } output = output.Distinct().ToList(); } /// /// 根据菜单id递归获取authorizeDataOutputModel的父级菜单. /// /// 菜单id. /// 选中菜单集合. /// 返回数据. private void GteModuleListById(string id, List authorizeModuleData, List output) { UsersCurrentAuthorizeMoldel? data = authorizeModuleData.Find(l => l.id == id); if (data != null) { if (!data.parentId.Equals("-1")) { if (!output.Contains(data)) output.Add(data); GteModuleListById(data.parentId, authorizeModuleData, output); } else { if (!output.Contains(data)) output.Add(data); } } } /// /// 获取验证码. /// /// 时间戳. /// private async Task GetCode(string timestamp) { string? cacheKey = string.Format("{0}{1}", CommonConst.CACHEKEYCODE, timestamp); return await _cacheManager.GetAsync(cacheKey); } /// /// 删除验证码. /// /// 时间戳. /// private Task DelCode(string timestamp) { string? cacheKey = string.Format("{0}{1}", CommonConst.CACHEKEYCODE, timestamp); _cacheManager.DelAsync(cacheKey); return Task.FromResult(true); } /// /// 删除用户登录信息缓存. /// /// 租户ID. /// 用户ID. /// private Task DelUserInfo(string tenantId, string userId) { string? cacheKey = string.Format("{0}:{1}:{2}", tenantId, CommonConst.CACHEKEYUSER, userId); _cacheManager.DelAsync(cacheKey); return Task.FromResult(true); } /// /// 密码策略验证. /// /// private async Task PwdStrategy(UsersCurrentActionsModifyPasswordInput input) { // 系统配置信息 var sysInfo = await _sysConfigService.GetInfo(); // 禁用旧密码 if (sysInfo.disableOldPassword == 1 && sysInfo.disableTheNumberOfOldPasswords > 0) { var oldPwdList = _repository.AsSugarClient().Queryable().Where(x => x.UserId == _userManager.UserId).OrderByDescending(o => o.CreatorTime).Take(sysInfo.disableTheNumberOfOldPasswords).ToList(); if (oldPwdList.Any()) { foreach (var item in oldPwdList) { if (MD5Encryption.Encrypt(input.password + item.Secretkey) == item.OldPassword.ToLower()) throw Oops.Oh(ErrorCode.D5026); } } } // 保存旧密码数据 var oldPwdEntity = new UserOldPasswordEntity(); oldPwdEntity.Id = SnowflakeIdHelper.NextId(); oldPwdEntity.UserId = _userManager.UserId; oldPwdEntity.Account = _userManager.Account; oldPwdEntity.OldPassword = MD5Encryption.Encrypt(input.password + _userManager.User.Secretkey); oldPwdEntity.Secretkey = _userManager.User.Secretkey; oldPwdEntity.CreatorTime = DateTime.Now; oldPwdEntity.TenantId = _userManager.TenantId; _repository.AsSugarClient().Insertable(oldPwdEntity).ExecuteCommand(); } #endregion }