优化鉴权系统
This commit is contained in:
+52
@@ -72,3 +72,55 @@ class UserUsageResponse(BaseModel):
|
||||
completion_tokens: int
|
||||
total_tokens: int
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class RegisterRequest(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
username: str
|
||||
password: str
|
||||
|
||||
@field_validator("username")
|
||||
@classmethod
|
||||
def validate_username(cls, value: str) -> str:
|
||||
if not value.strip():
|
||||
raise ValueError("username must not be blank")
|
||||
return value
|
||||
|
||||
@field_validator("password")
|
||||
@classmethod
|
||||
def validate_password(cls, value: str) -> str:
|
||||
if not value.strip():
|
||||
raise ValueError("password must not be blank")
|
||||
return value
|
||||
|
||||
|
||||
class RegisterResponse(BaseModel):
|
||||
user_id: str
|
||||
created_at: datetime
|
||||
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
username: str
|
||||
password: str
|
||||
|
||||
@field_validator("username")
|
||||
@classmethod
|
||||
def validate_username(cls, value: str) -> str:
|
||||
if not value.strip():
|
||||
raise ValueError("username must not be blank")
|
||||
return value
|
||||
|
||||
@field_validator("password")
|
||||
@classmethod
|
||||
def validate_password(cls, value: str) -> str:
|
||||
if not value.strip():
|
||||
raise ValueError("password must not be blank")
|
||||
return value
|
||||
|
||||
|
||||
class LoginResponse(BaseModel):
|
||||
user_id: str
|
||||
api_key: str
|
||||
Reference in New Issue
Block a user