2026-07-17 23:20:34 +02:00
|
|
|
"""Request/response models for the auth API (SPEC §9.1)."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RegisterRequest(BaseModel):
|
|
|
|
|
localpart: str = Field(min_length=3, max_length=30)
|
|
|
|
|
password: str = Field(min_length=8, max_length=1024)
|
|
|
|
|
recovery_email: str | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
|
|
|
# Accepts either a bare localpart or the full ``localpart@domain`` handle.
|
|
|
|
|
handle: str = Field(min_length=1, max_length=320)
|
|
|
|
|
password: str = Field(min_length=1, max_length=1024)
|
|
|
|
|
totp: str | None = None # required when the account has 2FA enabled
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TotpSetupResponse(BaseModel):
|
|
|
|
|
secret: str # base32, for manual entry
|
|
|
|
|
provisioning_uri: str # otpauth:// URI to render as a QR code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TotpEnableRequest(BaseModel):
|
|
|
|
|
code: str = Field(min_length=6, max_length=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TotpDisableRequest(BaseModel):
|
|
|
|
|
password: str = Field(min_length=1, max_length=1024)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SessionOut(BaseModel):
|
|
|
|
|
sid: str
|
|
|
|
|
created: str
|
|
|
|
|
ua: str
|
|
|
|
|
current: bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetRequestIn(BaseModel):
|
|
|
|
|
handle: str = Field(min_length=1, max_length=320)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PasswordResetIn(BaseModel):
|
|
|
|
|
token: str = Field(min_length=1)
|
|
|
|
|
password: str = Field(min_length=8, max_length=1024)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserOut(BaseModel):
|
|
|
|
|
id: uuid.UUID
|
|
|
|
|
handle: str
|
|
|
|
|
recovery_email: str | None
|
|
|
|
|
settings: dict[str, object]
|
|
|
|
|
totp_enabled: bool = False
|
2026-09-16 20:34:08 +02:00
|
|
|
is_admin: bool = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RegistrationStatusOut(BaseModel):
|
|
|
|
|
"""Public, unauthenticated: what the signup page should show."""
|
|
|
|
|
|
|
|
|
|
open: bool
|
|
|
|
|
# True when the instance has no users yet, so signup creates the administrator.
|
|
|
|
|
bootstrap: bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AdminSettingsOut(BaseModel):
|
|
|
|
|
registration_open: bool
|
|
|
|
|
default_quota_bytes: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AdminSettingsIn(BaseModel):
|
|
|
|
|
"""Merge semantics: omitted fields are left as they are."""
|
|
|
|
|
|
|
|
|
|
registration_open: bool | None = None
|
|
|
|
|
# Applies to users created after the change; existing mailboxes keep theirs.
|
|
|
|
|
default_quota_bytes: int | None = Field(default=None, gt=0)
|
2026-07-17 23:20:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class MessageOut(BaseModel):
|
|
|
|
|
status: str = "ok"
|