Skip to content

Commit

Permalink
refactor(code_verification): abort_if_invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Feb 22, 2025
1 parent 26c2e83 commit d9b2d6d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 6 additions & 0 deletions allauth/account/internal/flows/code_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def record_invalid_attempt(self) -> bool:
self.persist()
return True

def abort_if_invalid(self):
if not self.is_valid():
self.abort()
return None
return self

def is_valid(self) -> bool:
return time.time() - self.state["at"] <= self.timeout

Expand Down
4 changes: 1 addition & 3 deletions allauth/account/internal/flows/email_verification_by_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,4 @@ def resume(cls, request):
if not state:
return None
process = EmailVerificationProcess(request=request, state=state)
if not process.is_valid():
return None
return process
return process.abort_if_invalid()
4 changes: 1 addition & 3 deletions allauth/account/internal/flows/login_by_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,4 @@ def initiate(cls, *, request, user, email: str, stage=None):
@classmethod
def resume(cls, stage):
process = LoginCodeVerificationProcess(stage=stage)
if not process.is_valid():
return None
return process
return process.abort_if_invalid()
4 changes: 1 addition & 3 deletions allauth/account/internal/flows/password_reset_by_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,4 @@ def resume(
if not state:
return None
process = PasswordResetVerificationProcess(request, state=state)
if not process.is_valid():
return None
return process
return process.abort_if_invalid()

0 comments on commit d9b2d6d

Please sign in to comment.