mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
feat: 将 CreateUserRequest 邮箱字段改为可选
Closes #107 Co-authored-by: AAEE86 <ppk0227@hotmail.com>
This commit is contained in:
@@ -237,7 +237,7 @@ class CreateUserRequest(BaseModel):
|
|||||||
|
|
||||||
username: str = Field(..., min_length=2, max_length=50, description="用户名")
|
username: str = Field(..., min_length=2, max_length=50, description="用户名")
|
||||||
password: str = Field(..., min_length=6, max_length=128, description="密码")
|
password: str = Field(..., min_length=6, max_length=128, description="密码")
|
||||||
email: str = Field(..., min_length=3, max_length=255, description="邮箱地址")
|
email: Optional[str] = Field(None, max_length=255, description="邮箱地址(可选)")
|
||||||
role: Optional[UserRole] = Field(UserRole.USER, description="用户角色")
|
role: Optional[UserRole] = Field(UserRole.USER, description="用户角色")
|
||||||
quota_usd: Optional[float] = Field(default=None, description="USD配额,null表示使用系统默认配额")
|
quota_usd: Optional[float] = Field(default=None, description="USD配额,null表示使用系统默认配额")
|
||||||
unlimited: bool = Field(default=False, description="是否无限配额")
|
unlimited: bool = Field(default=False, description="是否无限配额")
|
||||||
@@ -258,20 +258,22 @@ class CreateUserRequest(BaseModel):
|
|||||||
raise ValueError("配额必须在 0-10000 范围内")
|
raise ValueError("配额必须在 0-10000 范围内")
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@field_validator("email")
|
@field_validator("email")
|
||||||
def validate_email(cls, v):
|
@classmethod
|
||||||
"""验证邮箱格式"""
|
def validate_email(cls, v: Optional[str]) -> Optional[str]:
|
||||||
|
"""验证邮箱格式(如果提供)"""
|
||||||
|
if v is None:
|
||||||
|
return None
|
||||||
v = v.strip()
|
v = v.strip()
|
||||||
if not v:
|
if not v:
|
||||||
raise ValueError("邮箱不能为空")
|
return None
|
||||||
email_pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
|
email_pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
|
||||||
if not re.match(email_pattern, v):
|
if not re.match(email_pattern, v):
|
||||||
raise ValueError("邮箱格式无效")
|
raise ValueError("邮箱格式无效")
|
||||||
return v.lower()
|
return v.lower()
|
||||||
|
|
||||||
@classmethod
|
|
||||||
@field_validator("username")
|
@field_validator("username")
|
||||||
|
@classmethod
|
||||||
def validate_username(cls, v):
|
def validate_username(cls, v):
|
||||||
"""验证用户名格式"""
|
"""验证用户名格式"""
|
||||||
v = v.strip()
|
v = v.strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user