feat:添加验证码调试功能
- 在验证码服务中添加debugCodeInfo方法 - 在业务层添加debugVerificationCode调试接口 - 新增/auth/debug-verification-code调试端点 - 支持查看验证码详细状态信息(TTL、尝试次数等) - 便于开发和生产环境问题排查
This commit is contained in:
@@ -343,4 +343,23 @@ export class LoginController {
|
|||||||
async resendEmailVerification(@Body() sendEmailVerificationDto: SendEmailVerificationDto): Promise<ApiResponse<{ verification_code?: string }>> {
|
async resendEmailVerification(@Body() sendEmailVerificationDto: SendEmailVerificationDto): Promise<ApiResponse<{ verification_code?: string }>> {
|
||||||
return await this.loginService.resendEmailVerification(sendEmailVerificationDto.email);
|
return await this.loginService.resendEmailVerification(sendEmailVerificationDto.email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调试验证码信息
|
||||||
|
* 仅用于开发和调试
|
||||||
|
*
|
||||||
|
* @param sendEmailVerificationDto 邮箱信息
|
||||||
|
* @returns 验证码调试信息
|
||||||
|
*/
|
||||||
|
@ApiOperation({
|
||||||
|
summary: '调试验证码信息',
|
||||||
|
description: '获取验证码的详细调试信息(仅开发环境)'
|
||||||
|
})
|
||||||
|
@ApiBody({ type: SendEmailVerificationDto })
|
||||||
|
@Post('debug-verification-code')
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
@UsePipes(new ValidationPipe({ transform: true }))
|
||||||
|
async debugVerificationCode(@Body() sendEmailVerificationDto: SendEmailVerificationDto): Promise<any> {
|
||||||
|
return await this.loginService.debugVerificationCode(sendEmailVerificationDto.email);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -427,4 +427,31 @@ export class LoginService {
|
|||||||
// 简单的Base64编码(实际应用中应使用JWT)
|
// 简单的Base64编码(实际应用中应使用JWT)
|
||||||
return Buffer.from(JSON.stringify(payload)).toString('base64');
|
return Buffer.from(JSON.stringify(payload)).toString('base64');
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 调试验证码信息
|
||||||
|
*
|
||||||
|
* @param email 邮箱地址
|
||||||
|
* @returns 调试信息
|
||||||
|
*/
|
||||||
|
async debugVerificationCode(email: string): Promise<any> {
|
||||||
|
try {
|
||||||
|
this.logger.log(`调试验证码信息: ${email}`);
|
||||||
|
|
||||||
|
const debugInfo = await this.loginCoreService.debugVerificationCode(email);
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: debugInfo,
|
||||||
|
message: '调试信息获取成功'
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`获取验证码调试信息失败: ${email}`, error instanceof Error ? error.stack : String(error));
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: error instanceof Error ? error.message : '获取调试信息失败',
|
||||||
|
error_code: 'DEBUG_VERIFICATION_CODE_FAILED'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -567,4 +567,16 @@ export class LoginCoreService {
|
|||||||
const phoneRegex = /^(\+\d{1,3}[- ]?)?\d{10,11}$/;
|
const phoneRegex = /^(\+\d{1,3}[- ]?)?\d{10,11}$/;
|
||||||
return phoneRegex.test(str.replace(/\s/g, ''));
|
return phoneRegex.test(str.replace(/\s/g, ''));
|
||||||
}
|
}
|
||||||
}
|
/**
|
||||||
|
* 调试验证码信息
|
||||||
|
*
|
||||||
|
* @param email 邮箱地址
|
||||||
|
* @returns 调试信息
|
||||||
|
*/
|
||||||
|
async debugVerificationCode(email: string): Promise<any> {
|
||||||
|
return await this.verificationService.debugCodeInfo(
|
||||||
|
email,
|
||||||
|
VerificationCodeType.EMAIL_VERIFICATION
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user