Coverage for api/auth/schema.py: 100.00%
57 statements
« prev ^ index » next coverage.py v7.9.2, created at 2026-01-25 13:05 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2026-01-25 13:05 +0000
1from typing import TypedDict, Optional
2from datetime import datetime
3from core.config import settings
4from pydantic import BaseModel, EmailStr, Field
6class LoginResult(TypedDict):
7 user: "UserResponse"
8 session_id: str = Field(..., description="Session ID")
9 access_token: str = Field(..., description="JWT access token")
11class SessionResult(TypedDict):
12 session_id: str = Field(..., description="Session ID")
13 access_token: str = Field(..., description="JWT access token")
15class UserRegister(BaseModel):
16 first_name: str = Field(..., min_length=1, max_length=50, description="First name")
17 last_name: str = Field(..., min_length=1, max_length=50, description="Last name")
18 email: EmailStr = Field(..., description="User email address")
19 phone: str = Field(..., min_length=1, max_length=20, description="Phone number")
20 password: str = Field(..., min_length=settings.PASSWORD_MIN_LENGTH, max_length=50, description="Password")
22class UserLogin(BaseModel):
23 email: EmailStr = Field(..., description="User email address")
24 password: str = Field(..., min_length=1, description="Password")
26class UserResponse(BaseModel):
27 id: str = Field(..., description="User ID")
28 first_name: str = Field(..., description="First name")
29 last_name: str = Field(..., description="Last name")
30 email: str = Field(..., description="User email address")
31 phone: str = Field(..., description="Phone number")
33class UserLoginResponse(BaseModel):
34 access_token: str = Field(..., description="JWT access token")
35 expires_at: datetime = Field(..., description="Token expiration time")
36 user: UserResponse = Field(..., description="User information")
38class TokenResponse(BaseModel):
39 access_token: str = Field(..., description="JWT access token")
40 expires_at: datetime = Field(..., description="Token expiration time")
42class ActionRequiredResponse(BaseModel):
43 action_type: str = Field(..., description="Action type for frontend routing: 'password_reset' or 'email_verification'")
44 token: Optional[str] = Field(default=None, description="Token for the password reset")
45 expires_at: Optional[str] = Field(default=None, description="Token expiration time (ISO format)")
47class LogoutRequest(BaseModel):
48 logout_all: bool = Field(False, description="Whether to logout from all devices")
50class ResetPasswordRequest(BaseModel):
51 new_password: str = Field(..., min_length=settings.PASSWORD_MIN_LENGTH, max_length=50, description="New password")
53class TokenValidationResponse(BaseModel):
54 is_valid: bool = Field(..., description="Whether the token is valid")
56class ForgotPasswordRequest(BaseModel):
57 email: EmailStr = Field(..., description="User email address")
59class PasswordResetCooldownResponse(BaseModel):
60 cooldown_seconds: int = Field(..., description="Remaining cooldown time in seconds")
62class EmailVerificationResponse(BaseModel):
63 message: str = Field(..., description="Verification result message")
65class EmailVerificationRequiredResponse(BaseModel):
66 expires_at: Optional[str] = Field(default=None, description="Token expiration time (ISO format)")
68class PasswordResetRequiredResponse(BaseModel):
69 reset_token: str = Field(..., description="Password reset token")
70 expires_at: str = Field(..., description="Token expiration time (ISO format)")
72class ResendVerificationRequest(BaseModel):
73 email: EmailStr = Field(..., description="Email address to resend verification")
75action_required_response_examples = {
76 "passwordReset": {
77 "summary": "Password reset required",
78 "value": {
79 "code": 202,
80 "message": "Password reset required",
81 "data": {
82 "action_type": "password_reset",
83 "token": "password_reset_token",
84 "expires_at": "2024-01-01T12:00:00+00:00"
85 }
86 }
87 },
88 "emailVerification": {
89 "summary": "Email verification required",
90 "value": {
91 "code": 202,
92 "message": "Email verification required",
93 "data": {
94 "action_type": "email_verification",
95 "token": None,
96 "expires_at": "2024-01-01T12:00:00+00:00"
97 }
98 }
99 }
100}