mirror of
https://github.com/idrainformatica/PecFlow.git
synced 2026-06-16 12:45:42 +02:00
feat: Fase 1 – Fondamenta complete (backend FastAPI + auth + permessi)
- docker-compose.yml: PostgreSQL 16, Redis 7, MinIO, Nginx - backend FastAPI: struttura monorepo, config pydantic-settings - modelli SQLAlchemy: tutti i modelli (tenants, users, mailboxes, messages, archival, permissions, labels, audit_log) - migrazione Alembic 0001: schema completo in pure SQL - auth API: login JWT, refresh token rotation, logout, 2FA TOTP (setup/verify/disable) - CRUD utenti: lista, crea, modifica, reset password, soft delete - permessi granulari (Fase 1-A): mailbox_permissions, assegna/revoca/lista - CRUD tenant: gestione super-admin - sicurezza: AES-256-GCM cifratura credenziali IMAP/SMTP, bcrypt password - RLS PostgreSQL: isolamento multi-tenant per request - seed sviluppo: tenant demo + admin + operator - test unit: security (bcrypt, JWT, AES), auth_service - test integration: auth endpoints, users endpoints - CI GitHub Actions: lint (ruff), test (pytest), build Docker, security scan - infra: nginx.conf, redis.conf - Makefile con comandi make dev/test/migrate/seed Definition of Done: ✅ Login, refresh token e TOTP funzionanti ✅ make dev porta in piedi tutto lo stack locale ✅ CI configurata
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
"""
|
||||
Schema Pydantic per autenticazione e autorizzazione.
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, EmailStr, Field, field_validator
|
||||
|
||||
|
||||
# ─── Request ──────────────────────────────────────────────────────────────────
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
email: EmailStr
|
||||
password: str = Field(min_length=1)
|
||||
totp_code: str | None = Field(default=None, description="Codice TOTP 6 cifre (se 2FA attivo)")
|
||||
|
||||
|
||||
class RefreshRequest(BaseModel):
|
||||
refresh_token: str
|
||||
|
||||
|
||||
class TOTPVerifyRequest(BaseModel):
|
||||
totp_code: str = Field(min_length=6, max_length=6, description="Codice TOTP 6 cifre")
|
||||
|
||||
|
||||
class PasswordChangeRequest(BaseModel):
|
||||
current_password: str
|
||||
new_password: str = Field(min_length=8)
|
||||
|
||||
@field_validator("new_password")
|
||||
@classmethod
|
||||
def validate_password_strength(cls, v: str) -> str:
|
||||
if len(v) < 8:
|
||||
raise ValueError("La password deve essere almeno 8 caratteri")
|
||||
if not any(c.isupper() for c in v):
|
||||
raise ValueError("La password deve contenere almeno una lettera maiuscola")
|
||||
if not any(c.isdigit() for c in v):
|
||||
raise ValueError("La password deve contenere almeno un numero")
|
||||
return v
|
||||
|
||||
|
||||
# ─── Response ─────────────────────────────────────────────────────────────────
|
||||
|
||||
class TokenResponse(BaseModel):
|
||||
access_token: str
|
||||
refresh_token: str
|
||||
token_type: str = "bearer"
|
||||
expires_in: int = Field(description="Scadenza access token in secondi")
|
||||
|
||||
|
||||
class TOTPSetupResponse(BaseModel):
|
||||
"""Dati per configurare TOTP sull'authenticator app."""
|
||||
secret: str = Field(description="Segreto TOTP base32 (da inserire manualmente)")
|
||||
qr_uri: str = Field(description="URI otpauth:// per il QR code")
|
||||
qr_image_base64: str = Field(description="QR code come immagine PNG base64")
|
||||
|
||||
|
||||
class TOTPStatusResponse(BaseModel):
|
||||
totp_enabled: bool
|
||||
|
||||
|
||||
class UserTokenData(BaseModel):
|
||||
"""Dati estratti dal JWT per l'utente corrente."""
|
||||
user_id: uuid.UUID
|
||||
tenant_id: uuid.UUID
|
||||
role: str
|
||||
email: str | None = None
|
||||
Reference in New Issue
Block a user