diff --git a/tone-page-server/src/verification/verification.service.ts b/tone-page-server/src/verification/verification.service.ts index 9168f51..340ac9b 100644 --- a/tone-page-server/src/verification/verification.service.ts +++ b/tone-page-server/src/verification/verification.service.ts @@ -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);