summaryrefslogtreecommitdiff
path: root/app/schemas/user.py
blob: a12ad1a423eeba3a14f5f81a739475df1ebe3e01 (plain)
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
from typing import Optional

from pydantic import BaseModel, EmailStr, Field, field_validator

from app.schemas.profile import ProfileRead

from .integrations import UserIntegrationRead


class UserCreate(BaseModel):
    username: str = Field(..., max_length=32)
    email: EmailStr
    password: str = Field(..., min_length=8)

    model_config = {
        "extra": "forbid",
    }


class UserRead(BaseModel):
    id: int
    username: str
    email: Optional[EmailStr] = None
    google_id: Optional[str] = None
    avatar_file: Optional[str] = None
    banner_file: Optional[str] = None
    has_password: bool
    premium: bool
    is_banned: bool
    is_moderator: bool
    profile: ProfileRead
    integrations: Optional[UserIntegrationRead] = None
    model_config = {
        "from_attributes": True,
    }


class MeResponse(BaseModel):
    authenticated: bool
    user: Optional[UserRead] = None


class ChangeUsername(BaseModel):
    username: str


class ChangeEmail(BaseModel):
    email: EmailStr
    password: str


class ChangePassword(BaseModel):
    current_password: str = Field(..., min_length=8)
    new_password: str = Field(..., min_length=8)
    repeat_password: str = Field(..., min_length=8)


class SetPassword(BaseModel):
    new_password: str = Field(..., min_length=8)
    repeat_password: str = Field(..., min_length=8)

    model_config = {
        "extra": "forbid",
    }