- 新建 modules/platform 三层模块(Domain/Application/Infrastructure) - 搬入 8 个实体(User/Role/Permission/UserRole/RolePermission/RefreshToken/Menu/Notification) - 新建 PlatformDbContext(连 platform 库)+ 8 个 EF 配置 + SeedData - 搬入 92 个 Application CQRS 文件 + 57 个 Host Endpoints - RagDbContext 瘦身:只留 RAG 专属表(KnowledgeBase/Document/ChatMessage/Conversation) - Handler 注入改为 PlatformDbContext - appsettings 新增 DatabaseNames:Platform - BuildFlowHostModule 注册 PlatformDbContext + DependsOn PlatformApplicationModule - Conversation 实体去掉 User 导航(跨模块不直接引用实体) - rag SeedData 清空(平台种子归 platform) - 暂移除测 platform 功能的 Rag.Tests(后续建 platform 测试项目) - build 0/0
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using BuildFlow.Platform.Infrastructure.Persistence;
|
|
using BuildFlow.Shared.Domain.Common;
|
|
|
|
namespace BuildFlow.Host.Endpoints.rag.Auth;
|
|
|
|
/// <summary>
|
|
/// 修改当前用户密码。验证旧密码后更新为新密码。
|
|
/// POST /api/user/change-password
|
|
/// </summary>
|
|
public class ChangePasswordEndpoint(PlatformDbContext db, ICurrentUserContext userContext)
|
|
: Endpoint<ChangePasswordRequest>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/user/change-password");
|
|
}
|
|
|
|
public override async Task HandleAsync(ChangePasswordRequest req, CancellationToken ct)
|
|
{
|
|
var userId = userContext.GetRequiredUserId();
|
|
|
|
var user = await db.Users
|
|
.FirstOrDefaultAsync(u => u.Id.ToString() == userId, ct)
|
|
?? throw new UnauthorizedException("用户不存在");
|
|
|
|
// 验证旧密码
|
|
if (!BCrypt.Net.BCrypt.Verify(req.OldPassword, user.PasswordHash))
|
|
{
|
|
throw new BusinessException("旧密码不正确");
|
|
}
|
|
|
|
// 新密码不能与旧密码相同
|
|
if (req.OldPassword == req.NewPassword)
|
|
{
|
|
throw new BusinessException("新密码不能与旧密码相同");
|
|
}
|
|
|
|
// 更新密码
|
|
user.PasswordHash = BCrypt.Net.BCrypt.HashPassword(req.NewPassword);
|
|
await db.SaveChangesAsync(ct);
|
|
|
|
await Send.OkAsync(ct);
|
|
}
|
|
}
|