Initial commit

This commit is contained in:
2026-11-05 08:28:15 +00:00
commit 08582a4f70
65 changed files with 1886 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import os
import jwt
from datetime import datetime, timedelta
class TokenService:
def __init__(self):
self.SECRET = os.getenv('TOKEN_SECRET')
self.ALGORITHM = os.getenv('TOKEN_ALGORITHM')
self.LIVE_HOUR_MINUTES = os.getenv('TOKEN_LIVE')
def GenerateToken(self, payload):
payload['exp'] = datetime.now() + timedelta(minutes = int(self.LIVE_HOUR_MINUTES))
return jwt.encode(payload, self.SECRET, self.ALGORITHM)
def ValidateToken(self, token: str):
try:
if os.getenv('ENVIRONMENT') == 'Development' and token == "1":
return True
return jwt.decode(token, self.SECRET, algorithms = self.ALGORITHM)
except jwt.InvalidTokenError as e:
return False