Spaces:
Sleeping
Sleeping
File size: 1,315 Bytes
cccf200 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """
User model for authentication and authorization.
"""
from typing import Optional
from datetime import datetime
from sqlmodel import SQLModel, Field
class User(SQLModel, table=True):
"""User entity for authentication."""
__tablename__ = "users"
id: Optional[int] = Field(default=None, primary_key=True)
email: str = Field(unique=True, index=True, max_length=255)
username: Optional[str] = Field(default=None, index=True, max_length=100)
hashed_password: str = Field(default="$2b$12$DUMMY_HASH_NO_PASSWORD", max_length=255)
is_active: bool = Field(default=True)
is_superuser: bool = Field(default=False)
created_at: datetime = Field(default_factory=datetime.utcnow)
updated_at: datetime = Field(default_factory=datetime.utcnow)
class UserCreate(SQLModel):
"""Schema for creating a new user."""
email: str = Field(max_length=255)
username: str = Field(max_length=100)
password: str = Field(min_length=8, max_length=100)
class UserLogin(SQLModel):
"""Schema for user login."""
username: str = Field(max_length=100)
password: str = Field(max_length=100)
class UserResponse(SQLModel):
"""Schema for user response (without sensitive data)."""
id: int
email: str
username: str
is_active: bool
created_at: datetime
|