feat(qr): add 3-second dynamic QR auto-rotation and global settings configuration (v3.8.46)

This commit is contained in:
2026-10-28 08:11:45 -03:00
parent 54c221e20e
commit 2d1fefa856
16 changed files with 600 additions and 64 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ from typing import Any
from database import db, get_db, engine, SessionLocal, session
from config.config import Config
__version__ = "3.8.45"
__version__ = "3.8.46"
class DummyContext:
def __enter__(self):
+9 -2
View File
@@ -32,12 +32,19 @@ class QRSecurityService:
return getattr(Config, 'SECRET_KEY', 'unicaba-secret-qr-key')
@classmethod
def generate_qr_token(cls, user: User, hours_valid: int = DEFAULT_VALID_HOURS) -> str:
def generate_qr_token(
cls,
user: User,
hours_valid: int = DEFAULT_VALID_HOURS,
valid_seconds: Optional[int] = None
) -> str:
"""
Emite un token JWT firmado de credencial institucional para el usuario.
Contiene identificación, rol, DNI y tiempo de expiración.
Soporta valid_seconds para tokens dinámicos rotativos anti-captura.
"""
now = datetime.now(timezone.utc)
exp_delta = timedelta(seconds=valid_seconds) if valid_seconds is not None else timedelta(hours=hours_valid)
payload = {
"sub": str(user.id),
"dni": user.document_number or "",
@@ -46,7 +53,7 @@ class QRSecurityService:
"type": cls.QR_TOKEN_TYPE,
"jti": str(uuid.uuid4())[:8],
"iat": now,
"exp": now + timedelta(hours=hours_valid)
"exp": now + exp_delta
}
return jwt.encode(payload, cls._get_secret(), algorithm="HS256")