mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-26 05:51:29 +00:00
refactor(auth): tz_aware expiration comparison
This commit is contained in:
parent
8453f62c74
commit
8badb9aaaf
|
@ -7,6 +7,7 @@ from typing import Optional
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from mnemonic import Mnemonic
|
from mnemonic import Mnemonic
|
||||||
|
|
||||||
|
from selfprivacy_api.utils.timeutils import ensure_tz_aware
|
||||||
from selfprivacy_api.repositories.tokens.redis_tokens_repository import (
|
from selfprivacy_api.repositories.tokens.redis_tokens_repository import (
|
||||||
RedisTokensRepository,
|
RedisTokensRepository,
|
||||||
)
|
)
|
||||||
|
@ -121,8 +122,9 @@ def get_new_api_recovery_key(
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Get new recovery key"""
|
"""Get new recovery key"""
|
||||||
if expiration_date is not None:
|
if expiration_date is not None:
|
||||||
current_time = datetime.now().timestamp()
|
expiration_date = ensure_tz_aware(expiration_date)
|
||||||
if expiration_date.timestamp() < current_time:
|
current_time = datetime.now(timezone.utc)
|
||||||
|
if expiration_date < current_time:
|
||||||
raise InvalidExpirationDate("Expiration date is in the past")
|
raise InvalidExpirationDate("Expiration date is in the past")
|
||||||
if uses_left is not None:
|
if uses_left is not None:
|
||||||
if uses_left <= 0:
|
if uses_left <= 0:
|
||||||
|
|
Loading…
Reference in a new issue