新增用户注册功能

This commit is contained in:
Cheng Zhou
2025-12-22 21:19:48 +08:00
parent 03fddba406
commit 6ddf9901a0
33 changed files with 1389 additions and 138 deletions
+3 -3
View File
@@ -32,11 +32,11 @@ async def create_user(
db: AsyncSession = Depends(get_db_session),
current_user=Depends(require_roles(["ADMIN"])),
) -> UserRead:
existing = await user_crud.get_by_username(db, user_in.username)
existing = await user_crud.get_by_email(db, user_in.email)
if existing:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="Username already exists",
detail="Email already exists",
)
user = await user_crud.create_user(db, user_in)
return user
@@ -64,7 +64,7 @@ async def delete_user(
current_user=Depends(require_roles(["ADMIN"])),
):
admin_password = payload.get("admin_password")
if not admin_password or not verify_password(admin_password, current_user.hashed_password):
if not admin_password or not verify_password(admin_password, current_user.password_hash):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="管理员密码错误")
db_user = await user_crud.get_by_id(db, user_id)
if not db_user: