From 66c24e2ebe377a51c57631b161ec35cc4258a849 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Wed, 17 Jul 2024 10:47:06 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=A2=9E=E5=8A=A0=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Identity/Controllers/UsersController.cs | 10 ++++++++++ .../Identity/Request/UserResetPasswordRequest.cs | 7 +++++++ Src/Dlhis.Sys/Identity/Services/IUserService.cs | 2 ++ .../Identity/Services/Implements/UserService.cs | 15 +++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 Src/Dlhis.Sys/Identity/Request/UserResetPasswordRequest.cs diff --git a/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs b/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs index c0b35b98..5232aa00 100644 --- a/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs +++ b/Src/Dlhis.Sys/Identity/Controllers/UsersController.cs @@ -98,4 +98,14 @@ public class UsersController : ControllerBase { await _userService.ResetLoginTenantAsync(request); } + + /// + /// 密码重置 + /// + /// + [HttpPost("password/reset")] + public async Task ResetPasswordAsync(UserResetPasswordRequest request) + { + await _userService.ResetPasswordAsync(request); + } } \ No newline at end of file diff --git a/Src/Dlhis.Sys/Identity/Request/UserResetPasswordRequest.cs b/Src/Dlhis.Sys/Identity/Request/UserResetPasswordRequest.cs new file mode 100644 index 00000000..9319650a --- /dev/null +++ b/Src/Dlhis.Sys/Identity/Request/UserResetPasswordRequest.cs @@ -0,0 +1,7 @@ +namespace Dlhis.Sys.Identity.Request; + +public class UserResetPasswordRequest +{ + public int UserId { get; set; } + public string Password { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Sys/Identity/Services/IUserService.cs b/Src/Dlhis.Sys/Identity/Services/IUserService.cs index 84c069e7..6f114ba3 100644 --- a/Src/Dlhis.Sys/Identity/Services/IUserService.cs +++ b/Src/Dlhis.Sys/Identity/Services/IUserService.cs @@ -22,4 +22,6 @@ public interface IUserService : IScopeDependency Task CreateUserAsync(UserCreateRequest request); Task ResetLoginTenantAsync(UserResetLoginTenantRequest request); + + Task ResetPasswordAsync(UserResetPasswordRequest request); } \ No newline at end of file diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs index 17f9e5cb..6525ca36 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/UserService.cs @@ -158,4 +158,19 @@ public class UserService : IUserService .Where(x => x.ClaimType == "tenants") .ExecuteCommandAsync(); } + + /// + public async Task ResetPasswordAsync(UserResetPasswordRequest request) + { + request.Password ??= "123456"; + var user = await _identityDbContext.Queryable().SingleAsync(x => x.Id == request.UserId); + if (user != null) + { + var hasher = new PasswordHasher(); + var password = hasher.HashPassword(user, request.Password); + user.PasswordHash = password; + + await _identityDbContext.UpdateAsync(user); + } + } } \ No newline at end of file