Change admin password
(
request: ChangePasswordRequest,
token: str = Depends(verify_admin_token)
)
| 761 | |
| 762 | @router.post("/api/admin/change-password") |
| 763 | async def change_password( |
| 764 | request: ChangePasswordRequest, |
| 765 | token: str = Depends(verify_admin_token) |
| 766 | ): |
| 767 | """Change admin password""" |
| 768 | admin_config = await db.get_admin_config() |
| 769 | |
| 770 | # Verify old password |
| 771 | if not AuthManager.verify_admin(admin_config.username, request.old_password): |
| 772 | raise HTTPException(status_code=400, detail="旧密码错误") |
| 773 | |
| 774 | # Update password and username in database |
| 775 | update_params = {"password": request.new_password} |
| 776 | if request.username: |
| 777 | update_params["username"] = request.username |
| 778 | |
| 779 | await db.update_admin_config(**update_params) |
| 780 | |
| 781 | # 🔥 Hot reload: sync database config to memory |
| 782 | await db.reload_config_to_memory() |
| 783 | |
| 784 | # 🔑 Invalidate all admin session tokens (force re-login for security) |
| 785 | active_admin_tokens.clear() |
| 786 | |
| 787 | return {"success": True, "message": "密码修改成功,请重新登录"} |
| 788 | |
| 789 | |
| 790 | # ========== Token Management ========== |
no test coverage detected