This commit is contained in:
root
2025-07-12 18:46:26 +08:00
parent b2ff4dba32
commit 0b9797ddef
2 changed files with 20 additions and 15 deletions

View File

@@ -92,13 +92,21 @@ pub async fn python_cli_auth_login(
app: AppHandle, app: AppHandle,
request: AuthLoginRequest, request: AuthLoginRequest,
) -> Result<PythonCliResponse, String> { ) -> Result<PythonCliResponse, String> {
let mut args = vec!["auth".to_string(), "login".to_string(), request.username, request.password]; let mut args = vec!["auth".to_string(), "login".to_string(), request.username_or_email];
if let Some(password) = request.password { if let Some(password) = request.password {
args.push("--password".to_string()); args.push("--password".to_string());
args.push(password); args.push(password);
} }
if request.verbose.unwrap_or(false) {
args.push("--verbose".to_string());
}
if request.json_output.unwrap_or(false) {
args.push("--json".to_string());
}
execute_python_cli_command(app, args, None).await execute_python_cli_command(app, args, None).await
} }
@@ -120,14 +128,6 @@ pub async fn python_cli_auth_register(
args.push(password); args.push(password);
} }
if request.verbose.unwrap_or(false) {
args.push("--verbose".to_string());
}
if request.json_output.unwrap_or(false) {
args.push("--json".to_string());
}
execute_python_cli_command(app, args, None).await execute_python_cli_command(app, args, None).await
} }

View File

@@ -64,16 +64,21 @@ class PythonCliAuth {
*/ */
async login(credentials: LoginCredentials): Promise<UserProfile> { async login(credentials: LoginCredentials): Promise<UserProfile> {
try { try {
const username_or_email = credentials.email || credentials.username; // 确定使用邮箱还是用户名登录
if (!username_or_email) { let username_or_email: string;
if (credentials.email) {
username_or_email = credentials.email;
} else if (credentials.username) {
username_or_email = credentials.username;
} else {
throw new Error('Email or username is required'); throw new Error('Email or username is required');
} }
const response: PythonCliAuthResponse = await invoke('python_cli_auth_login', { const response: PythonCliAuthResponse = await invoke('python_cli_auth_login', {
request: { request: {
username: credentials.username, username_or_email: username_or_email,
email: credentials.email, password: credentials.password,
password: credentials.password json_output: true
} }
}); });
@@ -133,7 +138,7 @@ class PythonCliAuth {
email: credentials.email, email: credentials.email,
password: credentials.password, password: credentials.password,
display_name: credentials.displayName, display_name: credentials.displayName,
json_output: true verbose: true
} }
}); });
console.log({ response }) console.log({ response })