-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser.py
74 lines (53 loc) · 1.6 KB
/
user.py
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
68
69
70
71
72
73
74
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
from email_validator import EmailNotValidError, validate_email
from pydantic import UUID4, ConfigDict, EmailStr, Field, HttpUrl, field_validator
from backend.app.schemas.base import SchemaBase
class Auth(SchemaBase):
username: str
password: str
class Auth2(Auth):
captcha: str
class CreateUser(Auth):
email: str = Field(..., example='user@example.com')
@field_validator('email')
@classmethod
def email_validate(cls, v: str):
try:
validate_email(v, check_deliverability=False).email
except EmailNotValidError:
raise ValueError('邮箱格式错误')
return v
class UpdateUser(SchemaBase):
username: str
email: str
phone: str | None = None
@field_validator('email')
@classmethod
def email_validate(cls, v: str):
try:
validate_email(v, check_deliverability=False).email
except EmailNotValidError:
raise ValueError('邮箱格式错误')
return v
class Avatar(SchemaBase):
url: HttpUrl = Field(..., description='头像 http 地址')
class GetUserInfo(UpdateUser):
model_config = ConfigDict(from_attributes=True)
id: int
uuid: UUID4
username: str
email: EmailStr
status: int
is_superuser: bool
avatar: str | None = None
phone: str | None = None
join_time: datetime.datetime
last_login_time: datetime.datetime | None = None
class DeleteUser(SchemaBase):
id: int
class ResetPassword(SchemaBase):
username: str
new_password: str
confirm_password: str