fix: 添加rpc 返回

This commit is contained in:
root 2025-07-12 18:27:41 +08:00
parent e7fbb3ca1f
commit de1b77065f
1 changed files with 6 additions and 37 deletions

View File

@ -9,11 +9,11 @@ from rich.table import Table
from rich.panel import Panel from rich.panel import Panel
import json import json
import getpass import getpass
from python_core.utils.jsonrpc_enhanced import create_response_handler
from python_core.api.auth_api import auth_api from python_core.api.auth_api import auth_api
from python_core.services.user_storage import user_storage from python_core.services.user_storage import user_storage
from python_core.utils.jwt_auth import jwt_auth from python_core.utils.jwt_auth import jwt_auth
from uuid import uuid4
console = Console() console = Console()
auth_app = typer.Typer(name="auth", help="用户认证管理命令") auth_app = typer.Typer(name="auth", help="用户认证管理命令")
@ -30,6 +30,7 @@ def register_user(
"""注册新用户""" """注册新用户"""
try: try:
response = create_response_handler(uuid4())
console.print(f"🆕 [bold blue]用户注册[/bold blue]") console.print(f"🆕 [bold blue]用户注册[/bold blue]")
console.print(f"用户名: {username}") console.print(f"用户名: {username}")
console.print(f"邮箱: {email}") console.print(f"邮箱: {email}")
@ -38,10 +39,8 @@ def register_user(
# 获取密码 # 获取密码
if not password: if not password:
password = getpass.getpass("请输入密码: ") response.error("[red]❌ 密码不能为空[/red]")
if not password: raise typer.Exit(1)
console.print("[red]❌ 密码不能为空[/red]")
raise typer.Exit(1)
# 执行注册 # 执行注册
result = auth_api.register({ result = auth_api.register({
@ -50,37 +49,7 @@ def register_user(
"password": password, "password": password,
"display_name": display_name "display_name": display_name
}) })
response.success(result)
if result["success"]:
if json_output:
# JSON格式输出
print(json.dumps(result, ensure_ascii=False, indent=2))
else:
console.print(f"\n✅ [bold green]注册成功![/bold green]")
console.print(f"用户ID: {result['data']['user']['id']}")
console.print(f"创建时间: {result['data']['user']['created_at']}")
if verbose:
# 显示详细信息
user_info = f"""
🆔 用户ID: {result['data']['user']['id']}
👤 用户名: {result['data']['user']['username']}
📧 邮箱: {result['data']['user']['email']}
🏷 显示名称: {result['data']['user']['display_name']}
📅 创建时间: {result['data']['user']['created_at']}
🔑 Token: {result['data']['token'][:50]}...
过期时间: {result['data']['expires_at']}
"""
panel = Panel(user_info.strip(), title="用户详情", border_style="green")
console.print(panel)
else:
if json_output:
print(json.dumps(result, ensure_ascii=False, indent=2))
else:
console.print(f"[red]❌ 注册失败: {result['message']}[/red]")
raise typer.Exit(1)
except Exception as e: except Exception as e:
console.print(f"[red]❌ 注册失败: {str(e)}[/red]") console.print(f"[red]❌ 注册失败: {str(e)}[/red]")
raise typer.Exit(1) raise typer.Exit(1)