From 64370c3206d3f723066e0abae22ed3fcc0ea74d7 Mon Sep 17 00:00:00 2001 From: moyin <244344649@qq.com> Date: Thu, 25 Dec 2025 20:48:53 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E9=9B=86=E6=88=90=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E5=86=B7=E5=8D=B4=E6=97=B6=E9=97=B4=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=B8=85=E9=99=A4=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在用户成功完成关键操作后自动清除验证码冷却时间: - 用户注册成功后清除邮箱验证码冷却时间 - 密码重置成功后清除密码重置验证码冷却时间 - 验证码登录成功后清除登录验证码冷却时间 清除失败不影响主流程,只记录警告日志,确保用户体验。 --- src/core/login_core/login_core.service.ts | 38 +++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/core/login_core/login_core.service.ts b/src/core/login_core/login_core.service.ts index 3d52626..a53f79f 100644 --- a/src/core/login_core/login_core.service.ts +++ b/src/core/login_core/login_core.service.ts @@ -239,6 +239,19 @@ export class LoginCoreService { email_verified: email ? true : false // 如果提供了邮箱且验证码验证通过,则标记为已验证 }); + // 注册成功后清除验证码冷却时间,方便用户后续操作 + if (email) { + try { + await this.verificationService.clearCooldown( + email, + VerificationCodeType.EMAIL_VERIFICATION + ); + } catch (error) { + // 清除冷却时间失败不影响注册流程,只记录日志 + console.warn(`清除验证码冷却时间失败: ${email}`, error); + } + } + // 如果提供了邮箱,发送欢迎邮件 if (email) { try { @@ -417,9 +430,22 @@ export class LoginCoreService { const passwordHash = await this.hashPassword(newPassword); // 更新密码 - return await this.usersService.update(user.id, { + const updatedUser = await this.usersService.update(user.id, { password_hash: passwordHash }); + + // 密码重置成功后清除验证码冷却时间 + try { + await this.verificationService.clearCooldown( + identifier, + VerificationCodeType.PASSWORD_RESET + ); + } catch (error) { + // 清除冷却时间失败不影响重置流程,只记录日志 + console.warn(`清除验证码冷却时间失败: ${identifier}`, error); + } + + return updatedUser; } /** @@ -701,7 +727,15 @@ export class LoginCoreService { throw error; } - // 5. 验证成功,返回用户信息 + // 5. 验证成功后清除验证码冷却时间 + try { + await this.verificationService.clearCooldown(identifier, verificationType); + } catch (error) { + // 清除冷却时间失败不影响登录流程,只记录日志 + console.warn(`清除验证码冷却时间失败: ${identifier}`, error); + } + + // 6. 验证成功,返回用户信息 return { user, isNewUser: false