from sqlalchemy import Column, Integer, String, ForeignKey from sqlalchemy.orm import relationship from config.database import Base from services.security import get_password_hash, verify_password class User(Base): __tablename__ = "users" id = Column(Integer, primary_key=True, index=True) username = Column(String, unique=True, index=True) email = Column(String, unique=True, index=True) hashed_password = Column(String) role_id = Column(Integer, ForeignKey("roles.id")) role = relationship("Role", back_populates="users") def set_password(self, password: str): self.hashed_password = get_password_hash(password) def check_password(self, password: str) -> bool: return verify_password(password, str(self.hashed_password))