
- Set up FastAPI application with SQLite database - Create User model with email and password fields - Implement JWT token-based authentication - Add user registration and login endpoints - Create protected user profile endpoints - Configure Alembic for database migrations - Add password hashing with bcrypt - Include CORS middleware and health endpoint - Update README with setup and usage instructions Environment variables required: - SECRET_KEY: JWT secret key for token signing
29 lines
564 B
Python
29 lines
564 B
Python
from pydantic import BaseModel, EmailStr
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
class UserBase(BaseModel):
|
|
email: EmailStr
|
|
|
|
class UserCreate(UserBase):
|
|
password: str
|
|
|
|
class UserLogin(BaseModel):
|
|
email: EmailStr
|
|
password: str
|
|
|
|
class User(UserBase):
|
|
id: int
|
|
is_active: bool
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str
|
|
|
|
class TokenData(BaseModel):
|
|
email: Optional[str] = None |