41 lines
877 B
Python
41 lines
877 B
Python
"""Authentication Pydantic schemas."""
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, ConfigDict, EmailStr, Field
|
|
|
|
|
|
class UserRegister(BaseModel):
|
|
"""Request model for user registration."""
|
|
|
|
username: str = Field(..., min_length=3, max_length=50)
|
|
email: EmailStr
|
|
password: str = Field(..., min_length=6)
|
|
|
|
|
|
class UserLogin(BaseModel):
|
|
"""Request model for user login."""
|
|
|
|
username: str
|
|
password: str
|
|
|
|
|
|
class Token(BaseModel):
|
|
"""Response model for JWT token."""
|
|
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
"""Response model for user data."""
|
|
|
|
id: int
|
|
username: str
|
|
email: str
|
|
avatar_url: Optional[str] = "/static/default-avatar.png"
|
|
bio: Optional[str] = ""
|
|
created_at: datetime
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|