
- Create User model and schema - Implement password hashing with bcrypt - Add JWT token-based authentication - Create user and auth endpoints - Update todo endpoints with user authentication - Add alembic migration for user model - Update README with new features
46 lines
906 B
Python
46 lines
906 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
email: EmailStr
|
|
username: str
|
|
is_active: Optional[bool] = True
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
password: str = Field(..., min_length=6)
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
email: Optional[EmailStr] = None
|
|
username: Optional[str] = None
|
|
password: Optional[str] = Field(None, min_length=6)
|
|
is_active: Optional[bool] = None
|
|
|
|
|
|
class User(UserBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
from_attributes = True
|
|
|
|
|
|
class UserInDB(User):
|
|
hashed_password: str
|
|
|
|
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
username: Optional[str] = None
|
|
email: Optional[str] = None
|
|
user_id: Optional[int] = None |