mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 17:08:30 +01:00
Mark if a verification code has been deleted (#2290)
This commit is contained in:
parent
01d5f40580
commit
7295a2052f
2 changed files with 10 additions and 3 deletions
|
@ -37,8 +37,9 @@ class OnlyPaidError(MailboxError):
|
||||||
|
|
||||||
|
|
||||||
class CannotVerifyError(MailboxError):
|
class CannotVerifyError(MailboxError):
|
||||||
def __init__(self, msg: str):
|
def __init__(self, msg: str, deleted_activation_code: bool = False):
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
|
self.deleted_activation_code = deleted_activation_code
|
||||||
|
|
||||||
|
|
||||||
MAX_ACTIVATION_TRIES = 3
|
MAX_ACTIVATION_TRIES = 3
|
||||||
|
@ -196,7 +197,10 @@ def verify_mailbox_code(user: User, mailbox_id: int, code: str) -> Mailbox:
|
||||||
if activation.tries >= MAX_ACTIVATION_TRIES:
|
if activation.tries >= MAX_ACTIVATION_TRIES:
|
||||||
LOG.i(f"User {user} failed to verify mailbox {mailbox_id} more than 3 times")
|
LOG.i(f"User {user} failed to verify mailbox {mailbox_id} more than 3 times")
|
||||||
clear_activation_codes_for_mailbox(mailbox)
|
clear_activation_codes_for_mailbox(mailbox)
|
||||||
raise CannotVerifyError("Invalid activation code. Please request another code.")
|
raise CannotVerifyError(
|
||||||
|
"Invalid activation code. Please request another code.",
|
||||||
|
deleted_activation_code=True,
|
||||||
|
)
|
||||||
if activation.created_at < arrow.now().shift(minutes=-15):
|
if activation.created_at < arrow.now().shift(minutes=-15):
|
||||||
LOG.i(
|
LOG.i(
|
||||||
f"User {user} failed to verify mailbox {mailbox_id} because code is too old"
|
f"User {user} failed to verify mailbox {mailbox_id} because code is too old"
|
||||||
|
|
|
@ -314,10 +314,13 @@ def test_verify_too_may():
|
||||||
output = mailbox_utils.create_mailbox(user, random_email())
|
output = mailbox_utils.create_mailbox(user, random_email())
|
||||||
output.activation.tries = mailbox_utils.MAX_ACTIVATION_TRIES
|
output.activation.tries = mailbox_utils.MAX_ACTIVATION_TRIES
|
||||||
Session.commit()
|
Session.commit()
|
||||||
with pytest.raises(mailbox_utils.CannotVerifyError):
|
try:
|
||||||
mailbox_utils.verify_mailbox_code(
|
mailbox_utils.verify_mailbox_code(
|
||||||
user, output.mailbox.id, output.activation.code
|
user, output.mailbox.id, output.activation.code
|
||||||
)
|
)
|
||||||
|
assert False
|
||||||
|
except mailbox_utils.CannotVerifyError as e:
|
||||||
|
assert e.deleted_activation_code
|
||||||
|
|
||||||
|
|
||||||
@mail_sender.store_emails_test_decorator
|
@mail_sender.store_emails_test_decorator
|
||||||
|
|
Loading…
Reference in a new issue