- Create User model with bcrypt password hashing - Add auth routes: register, login, refresh, me - Implement JWT access and refresh tokens - Add get_current_user dependency for protected routes - Update Task model with user_id foreign key for data isolation - Update TaskService to filter tasks by authenticated user - Add auth configuration (secret key, token expiry)
40 lines
767 B
Python
40 lines
767 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel, ConfigDict, Field, EmailStr
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
email: EmailStr
|
|
name: str = Field(..., min_length=1, max_length=100)
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
password: str = Field(..., min_length=8, max_length=100)
|
|
|
|
|
|
class UserLogin(BaseModel):
|
|
email: EmailStr
|
|
password: str
|
|
|
|
|
|
class UserResponse(UserBase):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: str
|
|
created_at: datetime
|
|
|
|
|
|
class TokenResponse(BaseModel):
|
|
access_token: str
|
|
refresh_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
class TokenRefresh(BaseModel):
|
|
refresh_token: str
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
user_id: Optional[str] = None
|
|
email: Optional[str] = None
|