Database stores times in UTC but serialized without timezone info, causing frontend to misinterpret as local time. Now all datetime fields include 'Z' suffix to indicate UTC, enabling proper timezone conversion in the browser. - Add UTCDatetimeBaseModel base class for Pydantic schemas - Update model to_dict() methods to append 'Z' suffix - Affects: tasks, users, sessions, audit logs, translations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
"""
|
|
Tool_OCR - Authentication Schemas
|
|
"""
|
|
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from pydantic import BaseModel, Field
|
|
|
|
from app.schemas.base import UTCDatetimeBaseModel
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
"""Login request schema"""
|
|
username: str = Field(..., min_length=3, max_length=50, description="Username")
|
|
password: str = Field(..., min_length=6, description="Password")
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"username": "admin",
|
|
"password": "password123"
|
|
}
|
|
}
|
|
|
|
|
|
class UserInfo(BaseModel):
|
|
"""User information schema"""
|
|
id: int
|
|
email: str
|
|
display_name: Optional[str] = None
|
|
|
|
|
|
class Token(BaseModel):
|
|
"""JWT token response schema"""
|
|
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")
|
|
user: Optional[UserInfo] = Field(None, description="User information (V2 only)")
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
"token_type": "bearer",
|
|
"expires_in": 3600,
|
|
"user": {
|
|
"id": 1,
|
|
"email": "user@example.com",
|
|
"display_name": "User Name"
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
"""Token payload data"""
|
|
user_id: Optional[int] = None
|
|
username: Optional[str] = None
|
|
email: Optional[str] = None
|
|
session_id: Optional[int] = None
|
|
|
|
|
|
class UserResponse(UTCDatetimeBaseModel):
|
|
"""User response schema"""
|
|
id: int
|
|
email: str
|
|
display_name: Optional[str] = None
|
|
created_at: Optional[datetime] = None
|
|
last_login: Optional[datetime] = None
|
|
is_active: bool = True
|