feat: 完成 NestJS 后端核心底座开发 (M1-M6) 和 Ant Design Vue 前端迁移
主要更新: 1. 后端核心底座完成 (M1-M6): - 健康检查、指标监控、分布式锁 - 事件总线、队列系统、事务管理 - 安全守卫、多租户隔离、存储适配器 - 审计日志、配置管理、多语言支持 2. 前端迁移到 Ant Design Vue: - 从 Element Plus 迁移到 Ant Design Vue - 完善 system 模块 (role/menu/dept) - 修复依赖和配置问题 3. 文档完善: - AI 开发工作流文档 - 架构约束和开发规范 - 项目进度跟踪 4. 其他改进: - 修复编译错误和类型问题 - 完善测试用例 - 优化项目结构
This commit is contained in:
@@ -30,7 +30,7 @@ export class AuthService {
|
||||
|
||||
// 调用AdminService验证用户名密码
|
||||
const adminUser = await this.validateAdminUser(username, password, siteId);
|
||||
|
||||
|
||||
if (!adminUser) {
|
||||
throw new UnauthorizedException('用户名或密码错误');
|
||||
}
|
||||
@@ -53,8 +53,11 @@ export class AuthService {
|
||||
|
||||
// 计算过期时间
|
||||
const expiresIn = this.configService.get('JWT_EXPIRES_IN', '7d');
|
||||
const refreshExpiresIn = this.configService.get('JWT_REFRESH_EXPIRES_IN', '30d');
|
||||
|
||||
const refreshExpiresIn = this.configService.get(
|
||||
'JWT_REFRESH_EXPIRES_IN',
|
||||
'30d',
|
||||
);
|
||||
|
||||
const expiresAt = this.calculateExpiryDate(expiresIn);
|
||||
const refreshExpiresAt = this.calculateExpiryDate(refreshExpiresIn);
|
||||
|
||||
@@ -99,8 +102,12 @@ export class AuthService {
|
||||
const { username, password, siteId = 0 } = loginDto;
|
||||
|
||||
// 调用MemberService验证用户名密码
|
||||
const memberUser = await this.validateMemberUser(username, password, siteId);
|
||||
|
||||
const memberUser = await this.validateMemberUser(
|
||||
username,
|
||||
password,
|
||||
siteId,
|
||||
);
|
||||
|
||||
if (!memberUser) {
|
||||
throw new UnauthorizedException('用户名或密码错误');
|
||||
}
|
||||
@@ -123,8 +130,11 @@ export class AuthService {
|
||||
|
||||
// 计算过期时间
|
||||
const expiresIn = this.configService.get('JWT_EXPIRES_IN', '7d');
|
||||
const refreshExpiresIn = this.configService.get('JWT_REFRESH_EXPIRES_IN', '30d');
|
||||
|
||||
const refreshExpiresIn = this.configService.get(
|
||||
'JWT_REFRESH_EXPIRES_IN',
|
||||
'30d',
|
||||
);
|
||||
|
||||
const expiresAt = this.calculateExpiryDate(expiresIn);
|
||||
const refreshExpiresAt = this.calculateExpiryDate(refreshExpiresIn);
|
||||
|
||||
@@ -175,7 +185,7 @@ export class AuthService {
|
||||
try {
|
||||
// 验证刷新Token
|
||||
const payload = this.jwtService.verify(refreshToken);
|
||||
|
||||
|
||||
// 检查数据库中的Token记录
|
||||
const tokenRecord = await this.authTokenRepository.findOne({
|
||||
where: { refreshToken, isRevoked: 0 },
|
||||
@@ -199,7 +209,9 @@ export class AuthService {
|
||||
|
||||
// 更新数据库中的Token
|
||||
tokenRecord.token = newAccessToken;
|
||||
tokenRecord.expiresAt = this.calculateExpiryDate(this.configService.get('JWT_EXPIRES_IN', '7d'));
|
||||
tokenRecord.expiresAt = this.calculateExpiryDate(
|
||||
this.configService.get('JWT_EXPIRES_IN', '7d'),
|
||||
);
|
||||
await this.authTokenRepository.save(tokenRecord);
|
||||
|
||||
return {
|
||||
@@ -239,7 +251,7 @@ export class AuthService {
|
||||
try {
|
||||
// 验证JWT Token
|
||||
const payload = this.jwtService.verify(token);
|
||||
|
||||
|
||||
// 检查数据库中的Token记录
|
||||
const tokenRecord = await this.authTokenRepository.findOne({
|
||||
where: { token, isRevoked: 0 },
|
||||
@@ -268,7 +280,12 @@ export class AuthService {
|
||||
/**
|
||||
* 撤销用户所有Token
|
||||
*/
|
||||
async revokeUserTokens(userId: number, userType: string, siteId: number = 0, reason: string = '管理员撤销') {
|
||||
async revokeUserTokens(
|
||||
userId: number,
|
||||
userType: string,
|
||||
siteId: number = 0,
|
||||
reason: string = '管理员撤销',
|
||||
) {
|
||||
const tokens = await this.authTokenRepository.find({
|
||||
where: { userId, userType, siteId, isRevoked: 0 },
|
||||
});
|
||||
@@ -344,7 +361,11 @@ export class AuthService {
|
||||
/**
|
||||
* 验证管理员用户
|
||||
*/
|
||||
private async validateAdminUser(username: string, password: string, siteId: number): Promise<any> {
|
||||
private async validateAdminUser(
|
||||
username: string,
|
||||
password: string,
|
||||
siteId: number,
|
||||
): Promise<any> {
|
||||
try {
|
||||
// 根据用户名查找管理员
|
||||
const admin = await this.adminService.getAdminByUsername(username);
|
||||
@@ -353,7 +374,10 @@ export class AuthService {
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
const isValidPassword = await this.adminService.validatePassword(admin.uid, password);
|
||||
const isValidPassword = await this.adminService.validatePassword(
|
||||
admin.uid,
|
||||
password,
|
||||
);
|
||||
if (!isValidPassword) {
|
||||
return null;
|
||||
}
|
||||
@@ -372,11 +396,15 @@ export class AuthService {
|
||||
/**
|
||||
* 验证会员用户
|
||||
*/
|
||||
private async validateMemberUser(username: string, password: string, siteId: number): Promise<any> {
|
||||
private async validateMemberUser(
|
||||
username: string,
|
||||
password: string,
|
||||
siteId: number,
|
||||
): Promise<any> {
|
||||
try {
|
||||
// 根据用户名查找会员
|
||||
let member = await this.memberService.findByUsername(username);
|
||||
|
||||
|
||||
// 如果用户名没找到,尝试用手机号或邮箱查找
|
||||
if (!member) {
|
||||
member = await this.memberService.findByMobile(username);
|
||||
@@ -405,4 +433,4 @@ export class AuthService {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user