修改只有一次验证机会的bug

This commit is contained in:
2026-03-26 02:04:41 +08:00
parent b18901a2d5
commit ca796a5fd2
5 changed files with 94 additions and 64 deletions
@@ -62,15 +62,16 @@ class EmailVerificationService:
def verify_code(self,email: str, code: str, purpose: VerificationPurpose):
email = email.lower()
code_hash = hash_verification_code(code)
stored_hash: Optional[str] = self.repo.consume_code(email, purpose)
stored = self.repo.compare_and_consume(email, purpose, code_hash)
if not stored_hash:
raise CodeExpiredError("Code expired or not found")
if stored_hash != hash_verification_code(code):
if stored == False:
raise CodeInvalidError("Invalid code")
if not stored:
raise CodeExpiredError("Code expired or not found")
return True
@lru_cache