123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using Furion.DatabaseAccessor.Extensions;
- using Microsoft.Extensions.Options;
- using YBEE.EQM.Core;
- namespace YBEE.EQM.Application;
- /// <summary>
- /// 系统用户服务
- /// </summary>
- public class SysUserService : ISysUserService, ITransient
- {
- private readonly IRepository<SysUser> _userRep;
- private readonly AuthOptions _authOptions;
- public SysUserService(IRepository<SysUser> userRep, IOptions<AuthOptions> options)
- {
- _userRep = userRep;
- _authOptions = options.Value;
- }
- /// <summary>
- /// 获取所有用户列表
- /// </summary>
- /// <returns></returns>
- public async Task<List<SysUserLiteOutput>> GetAllList()
- {
- var items = await _userRep.DetachedEntities.Where(u => u.Status == CommonStatus.ENABLE)
- .ProjectToType<SysUserLiteOutput>()
- .ToListAsync();
- return items;
- }
- /// <summary>
- /// 修改密码
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task ChangePassword(ChangeSysUserPasswordInput input)
- {
- string oldPwd = RSAEncryption.Decrypt(input.OldPassword, _authOptions.RsaPrivateKey);
- string newPwd = RSAEncryption.Decrypt(input.NewPassword, _authOptions.RsaPrivateKey);
- if (newPwd.Length < 6 || newPwd.Length > 32)
- {
- throw Oops.Oh(ErrorCode.E1006);
- }
- if ((await _userRep.DetachedEntities.AsQueryable().ToListAsync()).Any(t => t.Id == CurrentSysUserInfo.SysUserId && AESEncryption.Decrypt(t.Password, _authOptions.AesPassword).Equals(oldPwd)))
- {
- var user = await _userRep.FirstOrDefaultAsync(t => t.Id == CurrentSysUserInfo.SysUserId);
- user.Password = AESEncryption.Encrypt(newPwd, _authOptions.AesPassword);
- await user.UpdateIncludeNowAsync(new[] { "Password" });
- }
- else
- {
- throw Oops.Oh(ErrorCode.E1005);
- }
- }
- }
|