Step 2:用户 CRUD + bcrypt + JWT 真实鉴权 + RBAC 依赖
This commit is contained in:
@@ -4,24 +4,37 @@ from typing import Literal, Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
UserRole = Literal["PM", "CRA", "PV", "IMP", "ADMIN"]
|
||||
|
||||
|
||||
class UserBase(BaseModel):
|
||||
username: str = Field(min_length=1)
|
||||
role: Literal["PM", "CRA", "PV", "IMP"]
|
||||
role: UserRole
|
||||
is_active: bool = True
|
||||
|
||||
|
||||
class UserCreate(UserBase):
|
||||
class UserCreate(BaseModel):
|
||||
username: str = Field(min_length=1)
|
||||
password: str = Field(min_length=1)
|
||||
role: UserRole
|
||||
|
||||
|
||||
class UserRead(UserBase):
|
||||
class UserRead(BaseModel):
|
||||
id: uuid.UUID
|
||||
username: str
|
||||
role: UserRole
|
||||
is_active: bool
|
||||
created_at: datetime
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class UserUpdate(BaseModel):
|
||||
role: Optional[UserRole] = None
|
||||
is_active: Optional[bool] = None
|
||||
password: Optional[str] = Field(default=None, min_length=1)
|
||||
|
||||
|
||||
class UserInDB(UserBase):
|
||||
id: uuid.UUID
|
||||
hashed_password: str
|
||||
|
||||
Reference in New Issue
Block a user