fix
This commit is contained in:
@@ -24,7 +24,8 @@ def register_user(
|
||||
email: str = typer.Argument(..., help="邮箱地址"),
|
||||
display_name: Optional[str] = typer.Option(None, "--display-name", "-d", help="显示名称"),
|
||||
password: Optional[str] = typer.Option(None, "--password", "-p", help="密码(不提供则交互式输入)"),
|
||||
verbose: bool = typer.Option(False, "--verbose", "-v", help="详细输出")
|
||||
verbose: bool = typer.Option(False, "--verbose", "-v", help="详细输出"),
|
||||
json_output: bool = typer.Option(False, "--json", help="JSON格式输出")
|
||||
):
|
||||
"""注册新用户"""
|
||||
|
||||
@@ -51,13 +52,17 @@ def register_user(
|
||||
})
|
||||
|
||||
if result["success"]:
|
||||
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"""
|
||||
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']}
|
||||
@@ -65,12 +70,15 @@ def register_user(
|
||||
📅 创建时间: {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)
|
||||
"""
|
||||
|
||||
panel = Panel(user_info.strip(), title="用户详情", border_style="green")
|
||||
console.print(panel)
|
||||
else:
|
||||
console.print(f"[red]❌ 注册失败: {result['message']}[/red]")
|
||||
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:
|
||||
@@ -82,7 +90,8 @@ def register_user(
|
||||
def login_user(
|
||||
username_or_email: str = typer.Argument(..., help="用户名或邮箱"),
|
||||
password: Optional[str] = typer.Option(None, "--password", "-p", help="密码(不提供则交互式输入)"),
|
||||
verbose: bool = typer.Option(False, "--verbose", "-v", help="详细输出")
|
||||
verbose: bool = typer.Option(False, "--verbose", "-v", help="详细输出"),
|
||||
json_output: bool = typer.Option(False, "--json", help="JSON格式输出")
|
||||
):
|
||||
"""用户登录"""
|
||||
|
||||
@@ -104,13 +113,17 @@ def login_user(
|
||||
})
|
||||
|
||||
if result["success"]:
|
||||
console.print(f"\n✅ [bold green]登录成功![/bold green]")
|
||||
console.print(f"欢迎回来,{result['data']['user']['display_name']}!")
|
||||
console.print(f"最后登录: {result['data']['user']['last_login']}")
|
||||
|
||||
if verbose:
|
||||
# 显示详细信息
|
||||
user_info = f"""
|
||||
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"欢迎回来,{result['data']['user']['display_name']}!")
|
||||
console.print(f"最后登录: {result['data']['user']['last_login']}")
|
||||
|
||||
if verbose:
|
||||
# 显示详细信息
|
||||
user_info = f"""
|
||||
🆔 用户ID: {result['data']['user']['id']}
|
||||
👤 用户名: {result['data']['user']['username']}
|
||||
📧 邮箱: {result['data']['user']['email']}
|
||||
@@ -118,12 +131,15 @@ def login_user(
|
||||
🕒 最后登录: {result['data']['user']['last_login']}
|
||||
🔑 Token: {result['data']['token'][:50]}...
|
||||
⏰ 过期时间: {result['data']['expires_at']}
|
||||
"""
|
||||
|
||||
panel = Panel(user_info.strip(), title="登录信息", border_style="green")
|
||||
console.print(panel)
|
||||
"""
|
||||
|
||||
panel = Panel(user_info.strip(), title="登录信息", border_style="green")
|
||||
console.print(panel)
|
||||
else:
|
||||
console.print(f"[red]❌ 登录失败: {result['message']}[/red]")
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user