diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index e7b32a2d2..2910bdc46 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -100,32 +100,38 @@ namespace IRaCIS.Application.Services { //var dbUser = (await _userRepository.FirstOrDefaultAsync(t => t.Id == userId)).IfNullThrowException(); - if (oldPwd != null && oldPwd == newPwd) + if (_verifyConfig.CurrentValue.OpenUserComplexPassword) { - //---新密码与旧密码相同。 - throw new BusinessValidationFailedException(_localizer["User_NewOldPwdSame"]); + if (oldPwd != null && oldPwd == newPwd) + { + //---新密码与旧密码相同。 + throw new BusinessValidationFailedException(_localizer["User_NewOldPwdSame"]); + } + + + var dbUser = (await _userRepository.Where(t => t.Id == userId).FirstOrDefaultAsync()).IfNullThrowException(); + + if (oldPwd != null && dbUser.Password != oldPwd) + { + //---旧密码验证失败。 + throw new BusinessValidationFailedException(_localizer["User_OldPwdInvalid"]); + } + + if (dbUser.Password == newPwd) + { + //---新密码与旧密码相同。 + throw new BusinessValidationFailedException(_localizer["User_NewOldPwdSame"]); + } + + var passWordList = await _userPassWordLogRepository.Where(x => x.UserId == userId).OrderByDescending(x => x.CreateTime).Take(2).ToListAsync(); + + if (passWordList.Any(x => x.PassWord == newPwd)) + { + throw new BusinessValidationFailedException(_localizer["User_PassWordRepeat"]); + } + } - - var dbUser = (await _userRepository.Where(t => t.Id == userId).FirstOrDefaultAsync()).IfNullThrowException(); - - if (oldPwd != null && dbUser.Password != oldPwd) - { - //---旧密码验证失败。 - throw new BusinessValidationFailedException(_localizer["User_OldPwdInvalid"]); - } - - if (dbUser.Password == newPwd) - { - //---新密码与旧密码相同。 - throw new BusinessValidationFailedException(_localizer["User_NewOldPwdSame"]); - } - - var passWordList = await _userPassWordLogRepository.Where(x => x.UserId == userId).OrderByDescending(x => x.CreateTime).Take(2).ToListAsync(); - if (passWordList.Any(x => x.PassWord == newPwd)) - { - throw new BusinessValidationFailedException(_localizer["User_PassWordRepeat"]); - } if (oldPwd != null) { await _userPassWordLogRepository.AddAsync(new UserPassWordLog() @@ -137,7 +143,6 @@ namespace IRaCIS.Application.Services }); } - await _userRepository.BatchUpdateNoTrackingAsync(x => x.Id == userId, x => new User() { LastChangePassWordTime = DateTime.Now, @@ -145,7 +150,6 @@ namespace IRaCIS.Application.Services await _userPassWordLogRepository.SaveChangesAsync(); - await Task.CompletedTask; }