42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
"""
|
|
User authentication models
|
|
"""
|
|
from sqlalchemy import Column, Integer, String, Boolean, DateTime
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.models.base import BaseModel
|
|
|
|
|
|
class User(BaseModel):
|
|
"""
|
|
User authentication and authorization
|
|
"""
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
username = Column(String(50), unique=True, nullable=False, index=True)
|
|
email = Column(String(100), unique=True, nullable=False, index=True)
|
|
hashed_password = Column(String(100), nullable=False)
|
|
first_name = Column(String(50))
|
|
last_name = Column(String(50))
|
|
full_name = Column(String(100)) # Keep for backward compatibility
|
|
|
|
# Authorization
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
is_admin = Column(Boolean, default=False, nullable=False)
|
|
is_approver = Column(Boolean, default=False, nullable=False)
|
|
|
|
# User Preferences
|
|
theme_preference = Column(String(10), default='light') # 'light', 'dark'
|
|
|
|
# Activity tracking
|
|
last_login = Column(DateTime(timezone=True))
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
audit_logs = relationship("AuditLog", back_populates="user")
|
|
submitted_tickets = relationship("SupportTicket", foreign_keys="SupportTicket.user_id", back_populates="submitter")
|
|
|
|
def __repr__(self):
|
|
return f"<User(username='{self.username}', email='{self.email}')>" |