CLI - add command to clean blacklisted tokens
This commit is contained in:
@ -4,6 +4,8 @@ from typing import Optional
|
||||
import jwt
|
||||
from flask import current_app
|
||||
|
||||
from fittrackee.utils import clean
|
||||
|
||||
|
||||
def get_user_token(
|
||||
user_id: int, password_reset: Optional[bool] = False
|
||||
@ -45,3 +47,14 @@ def decode_user_token(auth_token: str) -> int:
|
||||
algorithms=['HS256'],
|
||||
)
|
||||
return payload['sub']
|
||||
|
||||
|
||||
def clean_blacklisted_tokens(days: int) -> int:
|
||||
"""
|
||||
Delete blacklisted tokens expired for more than provided number of days
|
||||
"""
|
||||
sql = """
|
||||
DELETE FROM blacklisted_tokens
|
||||
WHERE blacklisted_tokens.expired_at < %(limit)s;
|
||||
"""
|
||||
return clean(sql, days)
|
||||
|
Reference in New Issue
Block a user