2025-07-17 13:09:24 +02:00
|
|
|
"""
|
|
|
|
|
Authentication schemas
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel, EmailStr, Field, validator
|
|
|
|
|
from typing import Optional
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from app.core.config import settings
|
|
|
|
|
from shared.utils.validation import validate_spanish_phone
|
|
|
|
|
|
|
|
|
|
class UserRegistration(BaseModel):
|
|
|
|
|
"""User registration schema"""
|
|
|
|
|
email: EmailStr
|
|
|
|
|
password: str = Field(..., min_length=settings.PASSWORD_MIN_LENGTH)
|
|
|
|
|
full_name: str = Field(..., min_length=2, max_length=100)
|
|
|
|
|
phone: Optional[str] = None
|
2025-07-17 14:34:24 +02:00
|
|
|
language: str = Field(default="es", pattern="^(es|en)$")
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
@validator('password')
|
|
|
|
|
def validate_password(cls, v):
|
|
|
|
|
"""Validate password strength"""
|
|
|
|
|
from app.core.security import security_manager
|
|
|
|
|
if not security_manager.validate_password(v):
|
|
|
|
|
raise ValueError('Password does not meet security requirements')
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
@validator('phone')
|
|
|
|
|
def validate_phone(cls, v):
|
|
|
|
|
"""Validate phone number"""
|
|
|
|
|
if v and not validate_spanish_phone(v):
|
|
|
|
|
raise ValueError('Invalid Spanish phone number')
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
class UserLogin(BaseModel):
|
|
|
|
|
"""User login schema"""
|
|
|
|
|
email: EmailStr
|
|
|
|
|
password: str
|
|
|
|
|
|
|
|
|
|
class TokenResponse(BaseModel):
|
|
|
|
|
"""Token response schema"""
|
|
|
|
|
access_token: str
|
|
|
|
|
refresh_token: str
|
|
|
|
|
token_type: str = "bearer"
|
|
|
|
|
expires_in: int
|
|
|
|
|
|
|
|
|
|
class RefreshTokenRequest(BaseModel):
|
|
|
|
|
"""Refresh token request schema"""
|
|
|
|
|
refresh_token: str
|
|
|
|
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
|
|
|
"""User response schema"""
|
|
|
|
|
id: str
|
|
|
|
|
email: str
|
|
|
|
|
full_name: str
|
|
|
|
|
is_active: bool
|
|
|
|
|
is_verified: bool
|
|
|
|
|
tenant_id: Optional[str]
|
|
|
|
|
role: str
|
|
|
|
|
phone: Optional[str]
|
|
|
|
|
language: str
|
|
|
|
|
timezone: str
|
|
|
|
|
created_at: Optional[datetime]
|
|
|
|
|
last_login: Optional[datetime]
|
|
|
|
|
|
|
|
|
|
class PasswordChangeRequest(BaseModel):
|
|
|
|
|
"""Password change request schema"""
|
|
|
|
|
current_password: str
|
|
|
|
|
new_password: str = Field(..., min_length=settings.PASSWORD_MIN_LENGTH)
|
|
|
|
|
|
|
|
|
|
@validator('new_password')
|
|
|
|
|
def validate_new_password(cls, v):
|
|
|
|
|
"""Validate new password strength"""
|
|
|
|
|
from app.core.security import security_manager
|
|
|
|
|
if not security_manager.validate_password(v):
|
|
|
|
|
raise ValueError('New password does not meet security requirements')
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
class PasswordResetRequest(BaseModel):
|
|
|
|
|
"""Password reset request schema"""
|
|
|
|
|
email: EmailStr
|
|
|
|
|
|
|
|
|
|
class PasswordResetConfirm(BaseModel):
|
|
|
|
|
"""Password reset confirmation schema"""
|
|
|
|
|
token: str
|
|
|
|
|
new_password: str = Field(..., min_length=settings.PASSWORD_MIN_LENGTH)
|
|
|
|
|
|
|
|
|
|
@validator('new_password')
|
|
|
|
|
def validate_new_password(cls, v):
|
|
|
|
|
"""Validate new password strength"""
|
|
|
|
|
from app.core.security import security_manager
|
|
|
|
|
if not security_manager.validate_password(v):
|
|
|
|
|
raise ValueError('New password does not meet security requirements')
|
|
|
|
|
return v
|
|
|
|
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
|
|
|
"""User update schema"""
|
|
|
|
|
full_name: Optional[str] = Field(None, min_length=2, max_length=100)
|
|
|
|
|
phone: Optional[str] = None
|
2025-07-17 14:34:24 +02:00
|
|
|
language: Optional[str] = Field(None, pattern="^(es|en)$")
|
2025-07-17 13:09:24 +02:00
|
|
|
timezone: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
@validator('phone')
|
|
|
|
|
def validate_phone(cls, v):
|
|
|
|
|
"""Validate phone number"""
|
|
|
|
|
if v and not validate_spanish_phone(v):
|
|
|
|
|
raise ValueError('Invalid Spanish phone number')
|
|
|
|
|
return v
|