44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey, Enum as SQLEnum
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
import enum
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class RuoloUtente(str, enum.Enum):
|
|
"""Ruoli utente nell'applicazione"""
|
|
ADMIN = "admin"
|
|
OPERATORE = "operatore"
|
|
VISUALIZZATORE = "visualizzatore"
|
|
|
|
|
|
class Utente(Base):
|
|
"""Modello per gli utenti dell'applicazione"""
|
|
|
|
__tablename__ = "utenti"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
cliente_id = Column(Integer, ForeignKey("clienti.id"), nullable=False)
|
|
email = Column(String(255), unique=True, nullable=False, index=True)
|
|
password_hash = Column(String(255), nullable=False)
|
|
nome = Column(String(100), nullable=False)
|
|
cognome = Column(String(100), nullable=False)
|
|
telefono = Column(String(20))
|
|
ruolo = Column(SQLEnum(RuoloUtente), default=RuoloUtente.VISUALIZZATORE)
|
|
|
|
# FCM token per notifiche push
|
|
fcm_token = Column(String(500))
|
|
|
|
# Flags
|
|
attivo = Column(Boolean, default=True)
|
|
email_verificata = Column(Boolean, default=False)
|
|
|
|
# Metadata
|
|
ultimo_accesso = Column(DateTime(timezone=True))
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relazioni
|
|
cliente = relationship("Cliente", back_populates="utenti")
|