forked from mtusi2026/mtusi2026lab2
Complete lab
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, field_validator
|
||||
|
||||
|
||||
class ContractModel(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
@field_validator('*')
|
||||
def validate_text_encoding(cls, value, info):
|
||||
if isinstance(value, str):
|
||||
value.encode('utf-8')
|
||||
if info.field_name != 'password' and '\x00' in value:
|
||||
raise ValueError('NUL is not supported in PostgreSQL text')
|
||||
return value
|
||||
|
||||
|
||||
class Health(ContractModel):
|
||||
status: str
|
||||
|
||||
@@ -12,6 +12,7 @@ USERNAME_RE = re.compile(r"^[a-z0-9_]{3,32}$")
|
||||
class CreateUser(ContractModel):
|
||||
username: StrictStr
|
||||
display_name: StrictStr = Field(min_length=1, max_length=100)
|
||||
password: StrictStr = Field(min_length=12, max_length=128)
|
||||
|
||||
@field_validator("username")
|
||||
def validate_username(cls, value):
|
||||
|
||||
Reference in New Issue
Block a user