update handle
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 11m36s

This commit is contained in:
2025-06-16 20:41:03 +09:00
parent a4f7f867f5
commit d0746a7af6
3 changed files with 67 additions and 3 deletions

View File

@ -1,15 +1,40 @@
use crate::http_client::HttpClient;
use std::collections::HashMap;
use std::io::{self, Write};
pub async fn post_request(handle: String, pass: String, host: String, auth_factor_token: Option<String>) -> String {
// First attempt with provided 2FA code (if any)
let response = create_session_request(&handle, &pass, &host, auth_factor_token.as_deref()).await;
// Check if 2FA is required
if response.contains("AuthFactorTokenRequired") {
println!("🔐 2FA authentication required");
println!("📧 A sign-in code has been sent to your email address");
// Prompt for 2FA code
print!("Enter 2FA code: ");
io::stdout().flush().unwrap();
let mut code = String::new();
io::stdin().read_line(&mut code).unwrap();
let code = code.trim();
// Retry with 2FA code
println!("🔄 Retrying authentication with 2FA code...");
return create_session_request(&handle, &pass, &host, Some(code)).await;
}
response
}
async fn create_session_request(handle: &str, pass: &str, host: &str, auth_factor_token: Option<&str>) -> String {
let url = format!("https://{}/xrpc/com.atproto.server.createSession", host);
let mut map = HashMap::new();
map.insert("identifier", &handle);
map.insert("password", &pass);
map.insert("identifier", handle);
map.insert("password", pass);
// Add 2FA code if provided
if let Some(code) = &auth_factor_token {
if let Some(code) = auth_factor_token {
map.insert("authFactorToken", code);
}