diff --git a/app/routers/accounts.py b/app/routers/accounts.py index f8d32f6..c8b09bd 100644 --- a/app/routers/accounts.py +++ b/app/routers/accounts.py @@ -55,6 +55,15 @@ def delete_account(account_id: int, session: Session = Depends(get_session)) -> return account_service.delete_account(session, account_id) +@router.get( + "/{account_id}/password", + summary="查看账号登录密码明文(解密返回)", + dependencies=[Depends(require_api_key)], +) +def reveal_password(account_id: int, session: Session = Depends(get_session)) -> dict: + return account_service.reveal_password(session, account_id) + + @router.post( "/{account_id}/test", summary="测试账号凭证有效性(按账号所属平台的 SDK)", diff --git a/app/services/account_service.py b/app/services/account_service.py index 966abdf..408e3c8 100644 --- a/app/services/account_service.py +++ b/app/services/account_service.py @@ -109,3 +109,17 @@ def delete_account(session: Session, account_id: int) -> Dict[str, int]: session.commit() # 资产端保留原账号名文本(不级联清空),由用户自行处理 return {"affected_assets": affected} + + +def reveal_password(session: Session, account_id: int) -> Dict[str, str]: + """解密返回账号登录密码明文(供前端「查看密码」功能)。 + + 安全说明:接口受 API Key 保护;密码本可逆加密存储,此处合法解密还原。 + """ + account = _get_account(session, account_id) + plain = crypto.decrypt(account.login_password_encrypted) + if not plain: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, detail="该账号未配置登录密码" + ) + return {"login_user": account.login_user or "", "password": plain} diff --git a/static/js/modals.js b/static/js/modals.js index ff425e5..9a91b2f 100644 --- a/static/js/modals.js +++ b/static/js/modals.js @@ -291,6 +291,7 @@ const AccountsViewModal = {
{{ pwd.countdown }}s 后自动关闭
+