Step 2:用户 CRUD + bcrypt + JWT 真实鉴权 + RBAC 依赖

This commit is contained in:
Cheng Zhou
2025-12-16 16:15:28 +08:00
parent 223d445a94
commit 65df698570
44 changed files with 215 additions and 33 deletions
+16 -3
View File
@@ -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