fix: 添加rpc 返回
This commit is contained in:
parent
e7fbb3ca1f
commit
de1b77065f
|
|
@ -9,11 +9,11 @@ from rich.table import Table
|
|||
from rich.panel import Panel
|
||||
import json
|
||||
import getpass
|
||||
|
||||
from python_core.utils.jsonrpc_enhanced import create_response_handler
|
||||
from python_core.api.auth_api import auth_api
|
||||
from python_core.services.user_storage import user_storage
|
||||
from python_core.utils.jwt_auth import jwt_auth
|
||||
|
||||
from uuid import uuid4
|
||||
console = Console()
|
||||
auth_app = typer.Typer(name="auth", help="用户认证管理命令")
|
||||
|
||||
|
|
@ -30,6 +30,7 @@ def register_user(
|
|||
"""注册新用户"""
|
||||
|
||||
try:
|
||||
response = create_response_handler(uuid4())
|
||||
console.print(f"🆕 [bold blue]用户注册[/bold blue]")
|
||||
console.print(f"用户名: {username}")
|
||||
console.print(f"邮箱: {email}")
|
||||
|
|
@ -38,10 +39,8 @@ def register_user(
|
|||
|
||||
# 获取密码
|
||||
if not password:
|
||||
password = getpass.getpass("请输入密码: ")
|
||||
if not password:
|
||||
console.print("[red]❌ 密码不能为空[/red]")
|
||||
raise typer.Exit(1)
|
||||
response.error("[red]❌ 密码不能为空[/red]")
|
||||
raise typer.Exit(1)
|
||||
|
||||
# 执行注册
|
||||
result = auth_api.register({
|
||||
|
|
@ -50,37 +49,7 @@ def register_user(
|
|||
"password": password,
|
||||
"display_name": display_name
|
||||
})
|
||||
|
||||
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)
|
||||
|
||||
response.success(result)
|
||||
except Exception as e:
|
||||
console.print(f"[red]❌ 注册失败: {str(e)}[/red]")
|
||||
raise typer.Exit(1)
|
||||
|
|
|
|||
Loading…
Reference in New Issue