CLI - add command to clean blacklisted tokens

This commit is contained in:
Sam
2022-09-15 13:14:55 +02:00
parent e39fc3d211
commit 9b377c08e4
11 changed files with 161 additions and 18 deletions

View File

@ -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)