feat: 收口多品牌与模板构建基础

This commit is contained in:
que01 committed 2026-09-25 02:55:46 +08:00
1 parent 0425a1c672
commit 77224ea51f
317 files changed
+11290 -1158

No files matched your search

+21 -1
View File
@@ -7,7 +7,10 @@ import { signIdentity } from "./auth.js";
export class AdminAuthService {
constructor(private readonly prisma: PrismaService) {}
async login(username: string, password: string): Promise<{ token: string; displayName: string }> {
async login(
username: string,
password: string,
): Promise<{ token: string; displayName: string; mustChangePassword: boolean; role: string }> {
const user = await this.prisma.adminUser.findUnique({ where: { username } });
if (!user || !user.isEnabled || !(await bcrypt.compare(password, user.passwordHash))) {
throw new UnauthorizedException("账号或密码错误");
@@ -36,6 +39,23 @@ export class AdminAuthService {
role: "admin",
}),
displayName: user.displayName,
mustChangePassword: user.mustChangePassword,
role: activeMembership.role,
};
}
async changePassword(
userId: string,
currentPassword: string,
newPassword: string,
): Promise<void> {
const user = await this.prisma.adminUser.findUnique({ where: { id: userId } });
if (!user || !(await bcrypt.compare(currentPassword, user.passwordHash))) {
throw new UnauthorizedException("当前密码不正确");
}
await this.prisma.adminUser.update({
where: { id: userId },
data: { passwordHash: await bcrypt.hash(newPassword, 12), mustChangePassword: false },
});
}
}