diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs index 40d69d0c6..69021f38e 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserLogViewModel.cs @@ -25,6 +25,8 @@ namespace IRaCIS.Core.Application.ViewModel ///UserLogQuery 列表查询参数模型 public class UserLogQuery : PageInput { + public Guid? TrialId { get; set; } + public UserOptType? OptType { get; set; } public string? IP { get; set; } diff --git a/IRaCIS.Core.Application/Service/Management/UserLogService.cs b/IRaCIS.Core.Application/Service/Management/UserLogService.cs index 1aaf7aa27..b1233aaad 100644 --- a/IRaCIS.Core.Application/Service/Management/UserLogService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserLogService.cs @@ -18,21 +18,25 @@ namespace IRaCIS.Core.Application.Service { private readonly IRepository _userLogRepository; + private readonly IRepository _trialUserRepository; - public UserLogService(IRepository userLogRepository) + public UserLogService(IRepository userLogRepository, IRepository trialUserRepository) { _userLogRepository = userLogRepository; + _trialUserRepository = trialUserRepository; } + public async Task> GetUserLogList(UserLogQuery inQuery) { var userLogQueryable = _userLogRepository + .WhereIf(inQuery.TrialId != null, t => t.CreateUser.UserTrials.Any(c => c.TrialId == inQuery.TrialId && c.UserId == t.CreateUserId)) .WhereIf(inQuery.OptType!=null ,t=>t.OptType==inQuery.OptType) - .WhereIf(inQuery.BeginDate != null, t => t.CreateTime >= inQuery.BeginDate) - .WhereIf(inQuery.EndDate != null, t => t.CreateTime <= inQuery.EndDate) + .WhereIf(inQuery.BeginDate != null, t => t.CreateTime >= inQuery.BeginDate) + .WhereIf(inQuery.EndDate != null, t => t.CreateTime <= inQuery.EndDate) .WhereIf(!string.IsNullOrEmpty(inQuery.LoginName) , t => t.LoginName.Contains(inQuery.LoginName) ) .WhereIf(!string.IsNullOrEmpty(inQuery.IP), t => t.IP.Contains(inQuery.IP)) .WhereIf(!string.IsNullOrEmpty(inQuery.LoginName), t => t.LoginName.Contains(inQuery.LoginName)) diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 9305f852c..db3c324d9 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -295,6 +295,8 @@ namespace IRaCIS.Application.Services IsFirstAdd = true }); + await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, CreateUserId = _userInfo.Id, LoginName = _userInfo.UserName, IsSuccess = true, OptType = UserOptType.AdminResetPassword }, true); + return ResponseOutput.Ok(); } @@ -405,6 +407,8 @@ namespace IRaCIS.Application.Services IsFirstAdd = false }); + await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, CreateUserId = _userInfo.Id, LoginName =string.Empty,LoginPassword=newPwd, IsSuccess = true, OptType = UserOptType.ModifyPassword }, true); + return ResponseOutput.Result(success); } @@ -439,6 +443,7 @@ namespace IRaCIS.Application.Services IsFirstAdd = false }); + await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, CreateUserId = _userInfo.Id, LoginName = _userInfo.UserName, IsSuccess = true, OptType = UserOptType.ModifyPassword }, true); return ResponseOutput.Result(success); @@ -642,7 +647,7 @@ namespace IRaCIS.Application.Services if (failCount >= maxFailures) { - await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, CreateUserId = Guid.Empty, LoginName = userName, IsSuccess = false, OptType = UserOptType.AccountLocked }, true); + await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, CreateUserId = Guid.Empty, LoginName = userName,LoginPassword=password, IsSuccess = false, OptType = UserOptType.AccountLocked }, true); throw new BusinessValidationFailedException($"密码连续错误{maxFailures}次,当前账号已被限制登录,请等待 {lockoutMinutes} 分钟后再试。"); } @@ -677,7 +682,7 @@ namespace IRaCIS.Application.Services failCount++; _cache.Set(cacheKey, failCount, TimeSpan.FromMinutes(lockoutMinutes)); - await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, CreateUserId = Guid.Empty, LoginName = userName, IsSuccess = false, OptType = UserOptType.PasswordError }, true); + await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, CreateUserId = Guid.Empty, LoginName = userName, LoginPassword = password, IsSuccess = false, OptType = UserOptType.AccountOrPasswordError }, true); return ResponseOutput.NotOk(_localizer["User_CheckNameOrPw"], new LoginReturnDTO()); diff --git a/IRaCIS.Core.Domain/Management/UserLog.cs b/IRaCIS.Core.Domain/Management/UserLog.cs index 923eb84f2..0c78d92d0 100644 --- a/IRaCIS.Core.Domain/Management/UserLog.cs +++ b/IRaCIS.Core.Domain/Management/UserLog.cs @@ -38,6 +38,10 @@ namespace IRaCIS.Core.Domain.Models public bool IsSuccess { get; set; } + + [JsonIgnore] + public User CreateUser { get; set; } + } /// @@ -57,14 +61,18 @@ namespace IRaCIS.Core.Domain.Models LoginOut = 2, /// - /// 密码错误 + ///账号或者密码错误 /// - PasswordError = 3, + AccountOrPasswordError = 3, /// /// 账号锁定 /// - AccountLocked = 4 + AccountLocked = 4, + + ModifyPassword=5, + + AdminResetPassword=6 } }