
- Setup project structure and dependencies - Create SQLite database with SQLAlchemy models - Initialize Alembic for database migrations - Implement JWT-based authentication utilities - Create API endpoints for signup, login, and logout - Add health check endpoint - Implement authentication middleware for protected routes - Update README with setup and usage instructions - Add linting with Ruff
56 lines
1.0 KiB
Python
56 lines
1.0 KiB
Python
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
"""Base user schema."""
|
|
|
|
email: EmailStr
|
|
username: str
|
|
is_active: bool = True
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
"""User schema for creating new users."""
|
|
|
|
email: EmailStr
|
|
username: str
|
|
password: str = Field(..., min_length=8)
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
"""User schema for updating users."""
|
|
|
|
email: EmailStr | None = None
|
|
username: str | None = None
|
|
password: str | None = Field(None, min_length=8)
|
|
is_active: bool | None = None
|
|
|
|
|
|
class UserInDBBase(UserBase):
|
|
"""Base user schema with DB fields."""
|
|
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
"""Configuration for Pydantic model."""
|
|
|
|
from_attributes = True
|
|
|
|
|
|
class User(UserInDBBase):
|
|
"""User model returned to the client
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class UserInDB(UserInDBBase):
|
|
"""User model with password stored in DB
|
|
"""
|
|
|
|
hashed_password: str
|