mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
feat: 添加用户密码重置功能并优化用户管理界面
refactor(用户管理): 重构用户表单和详情展示逻辑 fix(用户管理): 修复性别显示和角色岗位选择问题 docs: 更新README文档和图片引用路径 style: 清理无用图片资源并更新样式
This commit is contained in:
@@ -14,6 +14,7 @@ from app.api.v1.params.system.user_param import UserQueryParams
|
||||
from app.api.v1.schemas.system.auth_schema import AuthSchema
|
||||
from app.api.v1.schemas.system.user_schema import (
|
||||
CurrentUserUpdateSchema,
|
||||
ResetPasswordSchema,
|
||||
UserCreateSchema,
|
||||
UserForgetPasswordSchema,
|
||||
UserRegisterSchema,
|
||||
@@ -66,6 +67,14 @@ async def change_current_user_password_controller(
|
||||
logger.info(f"修改密码成功: {result_dict}")
|
||||
return SuccessResponse(data=result_dict, msg='修改密码成功, 请重新登录')
|
||||
|
||||
@router.put("/reset/password", summary="重置密码", description="重置密码")
|
||||
async def change_current_user_password_controller(
|
||||
data: ResetPasswordSchema,
|
||||
auth: AuthSchema = Depends(get_current_user)
|
||||
) -> JSONResponse:
|
||||
result_dict = await UserService.reset_user_password_service(data=data, auth=auth)
|
||||
logger.info(f"重置密码成功: {result_dict}")
|
||||
return SuccessResponse(data=result_dict, msg='重置密码成功')
|
||||
|
||||
@router.post('/register', summary="注册用户", description="注册用户")
|
||||
async def register_user_controller(
|
||||
|
||||
@@ -53,6 +53,12 @@ class UserChangePasswordSchema(BaseModel):
|
||||
new_password: str = Field(default=None, max_length=128, description="新密码")
|
||||
|
||||
|
||||
class ResetPasswordSchema(BaseModel):
|
||||
"""修改密码"""
|
||||
id: int = Field(..., description="主键ID")
|
||||
password: str = Field(default=None, min_length=6, max_length=128, description="新密码")
|
||||
|
||||
|
||||
class UserCreateSchema(CurrentUserUpdateSchema):
|
||||
"""新增"""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@@ -19,6 +19,7 @@ from app.api.v1.schemas.system.auth_schema import AuthSchema
|
||||
from app.api.v1.schemas.system.menu_schema import MenuOutSchema
|
||||
from app.api.v1.schemas.system.user_schema import (
|
||||
CurrentUserUpdateSchema,
|
||||
ResetPasswordSchema,
|
||||
UserOutSchema,
|
||||
UserCreateSchema,
|
||||
UserUpdateSchema,
|
||||
@@ -244,6 +245,22 @@ class UserService:
|
||||
new_password_hash = PwdUtil.set_password_hash(password=data.new_password)
|
||||
new_user = await UserCRUD(auth).change_password_crud(id=user.id, password_hash=new_password_hash)
|
||||
return UserOutSchema.model_validate(new_user).model_dump()
|
||||
|
||||
@classmethod
|
||||
async def reset_user_password_service(cls, auth: AuthSchema, data: ResetPasswordSchema) -> Dict:
|
||||
"""修改用户密码"""
|
||||
if not data.password:
|
||||
raise CustomException(msg='密码不能为空')
|
||||
|
||||
# 验证用户
|
||||
user = await UserCRUD(auth).get_by_id_crud(id=data.id)
|
||||
if not user:
|
||||
raise CustomException(msg="用户不存在")
|
||||
|
||||
# 更新密码
|
||||
new_password_hash = PwdUtil.set_password_hash(password=data.new_password)
|
||||
new_user = await UserCRUD(auth).change_password_crud(id=user.id, password_hash=new_password_hash)
|
||||
return UserOutSchema.model_validate(new_user).model_dump()
|
||||
|
||||
@classmethod
|
||||
async def register_user_service(cls, auth: AuthSchema, data: UserRegisterSchema) -> Dict:
|
||||
|
||||
Reference in New Issue
Block a user