feat:集成验证码冷却时间自动清除机制
在用户成功完成关键操作后自动清除验证码冷却时间: - 用户注册成功后清除邮箱验证码冷却时间 - 密码重置成功后清除密码重置验证码冷却时间 - 验证码登录成功后清除登录验证码冷却时间 清除失败不影响主流程,只记录警告日志,确保用户体验。
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user