hang-S-002增加枚举,修改密码,重置密码,记录日志
							parent
							
								
									891af745bb
								
							
						
					
					
						commit
						ac3eaea3f6
					
				| 
						 | 
				
			
			@ -25,6 +25,8 @@ namespace IRaCIS.Core.Application.ViewModel
 | 
			
		|||
    ///<summary>UserLogQuery  列表查询参数模型</summary>
 | 
			
		||||
    public class UserLogQuery : PageInput
 | 
			
		||||
    {
 | 
			
		||||
        public Guid? TrialId { get; set; }
 | 
			
		||||
 | 
			
		||||
        public UserOptType? OptType { get; set; }
 | 
			
		||||
 | 
			
		||||
        public string? IP { get; set; }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,21 +18,25 @@ namespace IRaCIS.Core.Application.Service
 | 
			
		|||
    {
 | 
			
		||||
 | 
			
		||||
        private readonly IRepository<UserLog> _userLogRepository;
 | 
			
		||||
        private readonly IRepository<TrialUser> _trialUserRepository;
 | 
			
		||||
 | 
			
		||||
        public UserLogService(IRepository<UserLog> userLogRepository)
 | 
			
		||||
        public UserLogService(IRepository<UserLog> userLogRepository, IRepository<TrialUser> trialUserRepository)
 | 
			
		||||
        {
 | 
			
		||||
            _userLogRepository = userLogRepository;
 | 
			
		||||
            _trialUserRepository = trialUserRepository;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public async Task<PageOutput<UserLogView>> 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))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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());
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,6 +38,10 @@ namespace IRaCIS.Core.Domain.Models
 | 
			
		|||
 | 
			
		||||
        public bool IsSuccess { get; set; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        [JsonIgnore]
 | 
			
		||||
        public User CreateUser { get; set; }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
| 
						 | 
				
			
			@ -57,14 +61,18 @@ namespace IRaCIS.Core.Domain.Models
 | 
			
		|||
        LoginOut = 2,
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 密码错误
 | 
			
		||||
        ///账号或者密码错误
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        PasswordError = 3,
 | 
			
		||||
        AccountOrPasswordError = 3,
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 账号锁定
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        AccountLocked = 4
 | 
			
		||||
        AccountLocked = 4,
 | 
			
		||||
 | 
			
		||||
        ModifyPassword=5,
 | 
			
		||||
 | 
			
		||||
        AdminResetPassword=6
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue