101 lines
3.3 KiB
Python
101 lines
3.3 KiB
Python
"""Authentication schemas."""
|
|
|
|
from datetime import datetime
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
|
|
|
|
class UserRegisterRequest(BaseModel):
|
|
"""Schema for user registration request."""
|
|
|
|
email: EmailStr = Field(..., description="User email address")
|
|
password: str = Field(
|
|
...,
|
|
min_length=8,
|
|
description="User password (minimum 8 characters)",
|
|
)
|
|
name: str = Field(..., min_length=1, max_length=100, description="User full name")
|
|
|
|
|
|
class UserLoginRequest(BaseModel):
|
|
"""Schema for user login request."""
|
|
|
|
email: EmailStr = Field(..., description="User email address")
|
|
password: str = Field(..., description="User password")
|
|
|
|
|
|
class TokenResponse(BaseModel):
|
|
"""Schema for authentication token response."""
|
|
|
|
access_token: str = Field(..., description="JWT access token")
|
|
token_type: str = Field(default="bearer", description="Token type")
|
|
expires_in: int = Field(..., description="Token expiration time in seconds")
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
"""Schema for user information response."""
|
|
|
|
id: int = Field(..., description="User ID")
|
|
email: str = Field(..., description="User email address")
|
|
name: str = Field(..., description="User full name")
|
|
picture: str | None = Field(None, description="User profile picture URL")
|
|
role: str = Field(..., description="User role")
|
|
credits: int = Field(..., description="User credits")
|
|
is_active: bool = Field(..., description="Whether user is active")
|
|
plan: dict[str, Any] = Field(..., description="User plan information")
|
|
created_at: datetime = Field(..., description="User creation timestamp")
|
|
updated_at: datetime = Field(..., description="User last update timestamp")
|
|
|
|
|
|
class AuthResponse(BaseModel):
|
|
"""Schema for authentication response."""
|
|
|
|
user: UserResponse = Field(..., description="User information")
|
|
token: TokenResponse = Field(..., description="Authentication token")
|
|
|
|
|
|
class ApiTokenRequest(BaseModel):
|
|
"""Schema for API token generation request."""
|
|
|
|
expires_days: int = Field(
|
|
default=365,
|
|
ge=1,
|
|
le=3650,
|
|
description="Number of days until token expires (1-3650 days)",
|
|
)
|
|
|
|
|
|
class ApiTokenResponse(BaseModel):
|
|
"""Schema for API token response."""
|
|
|
|
api_token: str = Field(..., description="Generated API token")
|
|
expires_at: datetime | None = Field(None, description="Token expiration timestamp")
|
|
|
|
|
|
class ApiTokenStatusResponse(BaseModel):
|
|
"""Schema for API token status response."""
|
|
|
|
has_token: bool = Field(..., description="Whether user has an active API token")
|
|
expires_at: datetime | None = Field(None, description="Token expiration timestamp")
|
|
is_expired: bool = Field(..., description="Whether the token is expired")
|
|
|
|
|
|
class ChangePasswordRequest(BaseModel):
|
|
"""Schema for password change request."""
|
|
|
|
current_password: str | None = Field(None, description="Current password (required if user has existing password)")
|
|
new_password: str = Field(
|
|
...,
|
|
min_length=8,
|
|
description="New password (minimum 8 characters)",
|
|
)
|
|
|
|
|
|
class UpdateProfileRequest(BaseModel):
|
|
"""Schema for profile update request."""
|
|
|
|
name: str | None = Field(
|
|
None, min_length=1, max_length=100, description="User display name"
|
|
)
|