From b3de821d4e63cc5c7b142b51ae3e0737f585a409 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 14 Apr 2022 15:17:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E5=A4=A7=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Management/UserService.cs | 37 ++++++++++++++----- .../Context/IRaCISDBContext.cs | 1 + 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 0881a2d0a..45aa39f32 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -166,7 +166,7 @@ namespace IRaCIS.Application.Services var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == userId, u => new User() { Password = MD5Helper.Md5(StaticData.DefaultPassword), - PasswordChanged = false + IsFirstAdd = true }); return ResponseOutput.Result(success); @@ -265,13 +265,25 @@ namespace IRaCIS.Application.Services [HttpGet("{userId:guid}/{newPwd}")] public async Task AnonymousSetPassword(Guid userId, string newPwd) { - var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == userId, u => new User() - { - Password = newPwd, - PasswordChanged = true - }); - return ResponseOutput.Ok(success); + + var dbUser = await _userRepository.FirstOrDefaultAsync(t => t.Id == userId); + if (dbUser != null) + { + if (dbUser.Password == newPwd) + { + return ResponseOutput.NotOk("password not change"); + } + + var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == userId, u => new User() + { + Password = newPwd, + IsFirstAdd = false + }); + + return ResponseOutput.Result(success); + } + return ResponseOutput.NotOk("UserId 传递有误"); } /// @@ -298,8 +310,15 @@ namespace IRaCIS.Application.Services } //验证旧密码OK - if (await _userRepository.FirstOrDefaultAsync(t => t.Id == _userInfo.Id && t.Password == editPwModel.OldPassWord) != null) + var dbUser = await _userRepository.FirstOrDefaultAsync(t => t.Id == _userInfo.Id && t.Password == editPwModel.OldPassWord); + + if (dbUser != null) { + if (dbUser.Password == editPwModel.OldPassWord) + { + return ResponseOutput.NotOk("password not change"); + } + var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == _userInfo.Id, u => new User() { Password = editPwModel.NewPassWord, @@ -476,7 +495,7 @@ namespace IRaCIS.Application.Services var userLoginReturnModel = new LoginReturnDTO(); - var loginUser = await _userRepository.Where(u => u.UserName == userName && u.Password == password).ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync(); + var loginUser = await _userRepository.Where(u => u.UserName.Equals(userName) && u.Password == password).ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync(); if (loginUser == null) { diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index 5b482b7e3..bd3f72707 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -87,6 +87,7 @@ namespace IRaCIS.Core.Infra.EFCore modelBuilder.Entity().Property(t => t.FullName) .HasComputedColumnSql("[LastName] + ' / ' + [FirstName]",false); modelBuilder.Entity().Ignore(t => t.FullName); + //遍历实体模型手动配置 var typesToRegister = Assembly.GetExecutingAssembly().GetTypes().Where(q => q.GetInterface(typeof(IEntityTypeConfiguration<>).FullName) != null); foreach (var type in typesToRegister)