From 2249588e079d9e05a3526680a42e0d456d8d6634 Mon Sep 17 00:00:00 2001
From: MSuMshk <2039814060@qq.com>
Date: Mon, 15 Dec 2025 14:43:50 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E7=A7=9F=E6=88=B7?=
=?UTF-8?q?=E4=BC=AA=E8=A3=85=E7=99=BB=E5=BD=95=E4=B8=8E=E7=AE=A1=E7=90=86?=
=?UTF-8?q?=E5=91=98=E9=87=8D=E7=BD=AE=E9=93=BE=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/AuthController.cs | 25 ++++++-
.../Controllers/TenantsController.cs | 44 +++++++++++
.../CreateTenantAdminResetLinkTokenCommand.cs | 15 ++++
.../Commands/ImpersonateTenantCommand.cs | 16 ++++
...TenantAdminResetLinkTokenCommandHandler.cs | 73 ++++++++++++++++++
.../ImpersonateTenantCommandHandler.cs | 75 +++++++++++++++++++
.../IAdminPasswordResetTokenStore.cs | 25 +++++++
.../ResetAdminPasswordByTokenCommand.cs | 20 +++++
.../Contracts/ResetAdminPasswordRequest.cs | 18 +++++
...ResetAdminPasswordByTokenCommandHandler.cs | 57 ++++++++++++++
.../Repositories/IIdentityUserRepository.cs | 8 ++
.../Tenants/Enums/TenantAuditAction.cs | 12 ++-
.../Extensions/ServiceCollectionExtensions.cs | 4 +
.../Options/AdminPasswordResetOptions.cs | 13 ++++
.../Persistence/EfIdentityUserRepository.cs | 9 +++
.../RedisAdminPasswordResetTokenStore.cs | 66 ++++++++++++++++
16 files changed, 478 insertions(+), 2 deletions(-)
create mode 100644 src/Application/TakeoutSaaS.Application/App/Tenants/Commands/CreateTenantAdminResetLinkTokenCommand.cs
create mode 100644 src/Application/TakeoutSaaS.Application/App/Tenants/Commands/ImpersonateTenantCommand.cs
create mode 100644 src/Application/TakeoutSaaS.Application/App/Tenants/Handlers/CreateTenantAdminResetLinkTokenCommandHandler.cs
create mode 100644 src/Application/TakeoutSaaS.Application/App/Tenants/Handlers/ImpersonateTenantCommandHandler.cs
create mode 100644 src/Application/TakeoutSaaS.Application/Identity/Abstractions/IAdminPasswordResetTokenStore.cs
create mode 100644 src/Application/TakeoutSaaS.Application/Identity/Commands/ResetAdminPasswordByTokenCommand.cs
create mode 100644 src/Application/TakeoutSaaS.Application/Identity/Contracts/ResetAdminPasswordRequest.cs
create mode 100644 src/Application/TakeoutSaaS.Application/Identity/Handlers/ResetAdminPasswordByTokenCommandHandler.cs
create mode 100644 src/Infrastructure/TakeoutSaaS.Infrastructure/Identity/Options/AdminPasswordResetOptions.cs
create mode 100644 src/Infrastructure/TakeoutSaaS.Infrastructure/Identity/Services/RedisAdminPasswordResetTokenStore.cs
diff --git a/src/Api/TakeoutSaaS.AdminApi/Controllers/AuthController.cs b/src/Api/TakeoutSaaS.AdminApi/Controllers/AuthController.cs
index 22e9048..2545af7 100644
--- a/src/Api/TakeoutSaaS.AdminApi/Controllers/AuthController.cs
+++ b/src/Api/TakeoutSaaS.AdminApi/Controllers/AuthController.cs
@@ -1,6 +1,8 @@
+using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TakeoutSaaS.Application.Identity.Abstractions;
+using TakeoutSaaS.Application.Identity.Commands;
using TakeoutSaaS.Application.Identity.Contracts;
using TakeoutSaaS.Module.Authorization.Attributes;
using TakeoutSaaS.Shared.Abstractions.Constants;
@@ -14,10 +16,11 @@ namespace TakeoutSaaS.AdminApi.Controllers;
///
/// 提供登录、刷新 Token 以及用户权限查询能力。
/// 认证服务
+/// 中介者。
[ApiVersion("1.0")]
[Authorize]
[Route("api/admin/v{version:apiVersion}/auth")]
-public sealed class AuthController(IAdminAuthService authService) : BaseApiController
+public sealed class AuthController(IAdminAuthService authService, IMediator mediator) : BaseApiController
{
///
/// 登录获取 Token
@@ -65,6 +68,26 @@ public sealed class AuthController(IAdminAuthService authService) : BaseApiContr
return ApiResponse.Ok(response);
}
+ ///
+ /// 通过重置链接令牌重置管理员密码。
+ ///
+ /// 令牌为一次性使用;成功后即可使用新密码登录。
+ [HttpPost("reset-password")]
+ [AllowAnonymous]
+ [ProducesResponseType(typeof(ApiResponse