Spaces:
Running on T4
Running on T4
File size: 1,641 Bytes
2756f0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | """Auth request and response bodies."""
from typing import Annotated, Literal
from email_validator import EmailNotValidError, validate_email
from pydantic import AfterValidator, Field
from app.common.schemas import RequestModel, ResponseModel
from app.modules.accounts.schemas import UserOut
def normalize_email(value: str) -> str:
try:
return validate_email(value.strip(), check_deliverability=False).normalized.lower()
except EmailNotValidError as exc:
raise ValueError("Enter a valid email address.") from exc
Email = Annotated[str, Field(max_length=254), AfterValidator(normalize_email)]
Password = Annotated[str, Field(min_length=8, max_length=128)]
Role = Literal["player", "coach"]
class RegisterIn(RequestModel):
email: Email
password: Password
role: Role
class LoginIn(RequestModel):
email: Annotated[str, Field(min_length=1, max_length=254)]
password: Annotated[str, Field(min_length=1, max_length=128)]
class SocialIn(RequestModel):
provider: Literal["apple", "google"]
id_token: Annotated[str, Field(min_length=1, max_length=8192)]
role: Role = "player"
class RefreshIn(RequestModel):
refresh_token: Annotated[str, Field(min_length=1, max_length=256)]
class ForgotPasswordIn(RequestModel):
email: Email
class ResetPasswordIn(RequestModel):
token: Annotated[str, Field(min_length=1, max_length=256)]
password: Password
class TokensOut(ResponseModel):
access_token: str
refresh_token: str
expires_in: int
class AuthOut(ResponseModel):
user: UserOut
tokens: TokensOut
class SocialAuthOut(AuthOut):
is_new: bool
|