MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / change_password

Function change_password

src/api/admin.py:763–787  ·  view source on GitHub ↗

Change admin password

(
    request: ChangePasswordRequest,
    token: str = Depends(verify_admin_token)
)

Source from the content-addressed store, hash-verified

761
762@router.post("/api/admin/change-password")
763async 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 ==========

Callers 1

update_admin_passwordFunction · 0.85

Calls 5

get_admin_configMethod · 0.80
verify_adminMethod · 0.80
update_admin_configMethod · 0.80
clearMethod · 0.80

Tested by

no test coverage detected