58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
"""Authentication Pydantic models for the Aniworld web application.
|
|
|
|
This module defines simple request/response shapes used by the auth API and
|
|
by the authentication service. Keep models small and focused so they are
|
|
easy to validate and test.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field, constr
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
"""Request body for a login attempt.
|
|
|
|
Fields:
|
|
- password: master password string (minimum 8 chars recommended)
|
|
- remember: optional flag to request a long-lived session
|
|
"""
|
|
|
|
password: constr(min_length=1) = Field(..., description="Master password")
|
|
remember: Optional[bool] = Field(False, description="Keep session alive")
|
|
|
|
|
|
class LoginResponse(BaseModel):
|
|
"""Response returned after a successful login."""
|
|
|
|
access_token: str = Field(..., description="JWT access token")
|
|
token_type: str = Field("bearer", description="Token type")
|
|
expires_at: Optional[datetime] = Field(None, description="Optional expiry timestamp")
|
|
|
|
|
|
class SetupRequest(BaseModel):
|
|
"""Request to initialize the master password during first-time setup."""
|
|
|
|
master_password: constr(min_length=8) = Field(..., description="New master password")
|
|
|
|
|
|
class AuthStatus(BaseModel):
|
|
"""Public status about whether auth is configured and the current user state."""
|
|
|
|
configured: bool = Field(..., description="Whether a master password is set")
|
|
authenticated: bool = Field(False, description="Whether the caller is authenticated")
|
|
|
|
|
|
class SessionModel(BaseModel):
|
|
"""Lightweight session representation stored/returned by the auth service.
|
|
|
|
This model can be persisted if a persistent session store is used.
|
|
"""
|
|
|
|
session_id: str = Field(..., description="Unique session identifier")
|
|
user: Optional[str] = Field(None, description="Username or identifier")
|
|
created_at: datetime = Field(default_factory=datetime.utcnow)
|
|
expires_at: Optional[datetime] = Field(None)
|