添加邮件限流

This commit is contained in:
2025-06-19 11:41:30 +08:00
parent de09f0e928
commit 29cea18585

View File

@@ -47,14 +47,15 @@ export class VerificationService {
// 生成验证码
const code = this.generateCode();
// 存储验证码
this.saveCode(key, code);
this.logger.log(`Email[${email}] code: ${code}`);
// 发送验证码
await this.notificationService.sendMail({ type: 'login-verify', targetMail: email, code, }).catch(() => {
throw new BadRequestException('发送失败,请稍后再试')
this.clearCode(key);
throw new BadRequestException('发送失败,请稍后再试');
})
// 存储验证码
this.saveCode(key, code);
return true;
}
@@ -82,6 +83,10 @@ export class VerificationService {
});
}
private clearCode(key: string) {
this.pool.delete(key);
}
verifyPhoneCode(phone: string, code: string, type: 'login') {
const key = `phone:${phone}:${type}`;
return this.verifyCode(key, code);