Coverage for opt/mealie/lib/python3.12/site-packages/mealie/schema/user/registration.py: 100%
35 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 03:04 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 03:04 +0000
1from typing import Annotated
3from pydantic import Field, StringConstraints, field_validator
4from pydantic_core.core_schema import ValidationInfo
6from mealie.schema._mealie import MealieModel
7from mealie.schema._mealie.validators import validate_locale
10class CreateUserRegistration(MealieModel):
11 group: str | None = None
12 household: str | None = None
13 group_token: Annotated[str | None, Field(validate_default=True)] = None
14 email: Annotated[str, StringConstraints(to_lower=True, strip_whitespace=True)]
15 username: Annotated[str, StringConstraints(to_lower=True, strip_whitespace=True)]
16 full_name: Annotated[str, StringConstraints(strip_whitespace=True)]
17 password: str
18 password_confirm: str
19 advanced: bool = False
20 private: bool = False
22 seed_data: bool = False
23 locale: str = "en-US"
25 @field_validator("locale")
26 def valid_locale(cls, v):
27 if not validate_locale(v):
28 raise ValueError("invalid locale")
29 return v
31 @field_validator("password_confirm")
32 @classmethod
33 def passwords_match(cls, value, info: ValidationInfo):
34 if "password" in info.data and value != info.data["password"]:
35 raise ValueError("passwords do not match")
36 return value
38 @field_validator("group_token")
39 @classmethod
40 def group_or_token(cls, value, info: ValidationInfo):
41 if not bool(value) and not bool(info.data["group"]):
42 raise ValueError("group or group_token must be provided")
44 return value