From 4b15bcdc55a7f25d49525f681b49b1457cecb6e2 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 10 Jul 2024 10:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=E5=90=8E=E7=AB=AF=E6=AD=A3?= =?UTF-8?q?=E5=BC=8F=E7=8E=AF=E5=A2=83=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Management/UserService.cs | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) 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; }