24 lines
690 B
Python
24 lines
690 B
Python
from typing import Optional
|
|
|
|
from pydantic import BaseModel, EmailStr, root_validator
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
"""
|
|
Login schema with flexible identifier (email or username)
|
|
"""
|
|
# Either email or username must be provided
|
|
email: Optional[EmailStr] = None
|
|
username: Optional[str] = None
|
|
password: str
|
|
|
|
@root_validator
|
|
def check_email_or_username(cls, values):
|
|
"""
|
|
Validate that either email or username is provided
|
|
"""
|
|
email, username = values.get("email"), values.get("username")
|
|
if not email and not username:
|
|
raise ValueError("Either email or username must be provided")
|
|
return values
|