67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
"""
|
|
Pydantic schemas for User-related data structures
|
|
Defines request/response models for authentication endpoints
|
|
"""
|
|
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from uuid import UUID
|
|
|
|
class UserBase(BaseModel):
|
|
"""Base schema for user data"""
|
|
username: str = Field(..., min_length=3, max_length=50, description="Unique username")
|
|
email: EmailStr = Field(..., description="Valid email address")
|
|
|
|
class UserCreate(UserBase):
|
|
"""Schema for user registration request"""
|
|
password: str = Field(..., min_length=8, description="Password (min 8 characters)")
|
|
|
|
class UserLogin(BaseModel):
|
|
"""Schema for user login request"""
|
|
email: EmailStr = Field(..., description="User's email address")
|
|
password: str = Field(..., description="User's password")
|
|
|
|
class UserUpdate(BaseModel):
|
|
"""Schema for user profile updates"""
|
|
username: Optional[str] = Field(None, min_length=3, max_length=50)
|
|
email: Optional[EmailStr] = None
|
|
is_active: Optional[bool] = None
|
|
|
|
class UserResponse(UserBase):
|
|
"""Schema for user response data"""
|
|
id: UUID
|
|
created_at: datetime
|
|
is_active: bool
|
|
|
|
class Config:
|
|
from_attributes = True # Enable ORM mode
|
|
|
|
class Token(BaseModel):
|
|
"""Schema for JWT token response (login / refresh)"""
|
|
access_token: str = Field(..., description="JWT access token")
|
|
refresh_token: str = Field(..., description="Opaque refresh token")
|
|
token_type: str = Field(default="bearer", description="Token type")
|
|
expires_in: int = Field(..., description="Access token expiration time in seconds")
|
|
|
|
|
|
class AuthResponse(BaseModel):
|
|
"""Schema for authentication response with user info"""
|
|
access_token: str
|
|
refresh_token: str
|
|
token_type: str = "bearer"
|
|
expires_in: int
|
|
user: UserResponse
|
|
|
|
|
|
class RefreshTokenRequest(BaseModel):
|
|
"""Schema for token refresh request"""
|
|
refresh_token: str = Field(..., description="The refresh token to exchange")
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
"""Schema for decoded token payload"""
|
|
sub: str = Field(..., description="Subject (user ID)")
|
|
username: str = Field(..., description="Username")
|
|
exp: Optional[int] = None
|