Spaces:
Running
Running
| """User model for authentication and profiles.""" | |
| from datetime import datetime | |
| from enum import Enum as PyEnum | |
| from sqlalchemy import Column, String, Boolean, DateTime, Enum, Text | |
| from sqlalchemy.orm import relationship | |
| from uuid import uuid4 | |
| from app.database import Base | |
| class UserRole(str, PyEnum): | |
| STUDENT = "student" | |
| INSTRUCTOR = "instructor" | |
| ADMIN = "admin" | |
| class User(Base): | |
| __tablename__ = "users" | |
| id = Column(String(36), primary_key=True, default=lambda: str(uuid4())) | |
| email = Column(String(255), unique=True, nullable=False, index=True) | |
| hashed_password = Column(String(255), nullable=False) | |
| full_name = Column(String(255), nullable=False) | |
| avatar_url = Column(String(500), nullable=True) | |
| role = Column(Enum(UserRole), default=UserRole.STUDENT, nullable=False) | |
| is_active = Column(Boolean, default=True) | |
| is_verified = Column(Boolean, default=False) | |
| bio = Column(Text, nullable=True) | |
| # Timestamps | |
| created_at = Column(DateTime, default=datetime.utcnow) | |
| updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) | |
| last_login = Column(DateTime, nullable=True) | |
| # Relationships | |
| enrollments = relationship("Enrollment", back_populates="student", cascade="all, delete-orphan") | |
| progress_records = relationship("Progress", back_populates="student", cascade="all, delete-orphan") | |
| quiz_attempts = relationship("QuizAttempt", back_populates="student", cascade="all, delete-orphan") | |
| forum_posts = relationship("ForumPost", back_populates="author", cascade="all, delete-orphan") | |
| forum_comments = relationship("ForumComment", back_populates="author", cascade="all, delete-orphan") | |
| def __repr__(self): | |
| return f"<User {self.email}>" | |