Automated Action aae9527254 Set up user authentication flow with FastAPI and SQLite
- Created user model with SQLAlchemy ORM
- Implemented authentication with JWT tokens (access and refresh tokens)
- Added password hashing with bcrypt
- Created API endpoints for registration, login, and user management
- Set up Alembic for database migrations
- Added health check endpoint
- Created role-based access control (standard users and superusers)
- Added comprehensive documentation
2025-06-10 15:58:57 +00:00

46 lines
996 B
Python

from typing import Optional
from pydantic import BaseModel, EmailStr, Field, validator
# Shared properties
class UserBase(BaseModel):
email: Optional[EmailStr] = None
username: Optional[str] = None
is_active: Optional[bool] = True
is_superuser: bool = False
full_name: Optional[str] = None
# Properties to receive on user creation
class UserCreate(UserBase):
email: EmailStr
username: str
password: str = Field(..., min_length=8)
@validator("username")
def username_alphanumeric(cls, v):
if not v.isalnum():
raise ValueError("Username must be alphanumeric")
return v
# Properties to receive on user update
class UserUpdate(UserBase):
password: Optional[str] = None
# Properties to return to client
class User(UserBase):
id: int
class Config:
orm_mode = True
# Properties properties stored in JWT token
class UserInDB(User):
hashed_password: str
class Config:
orm_mode = True