This commit is contained in:
Mikhail Kilin
2026-01-20 00:57:28 +03:00
parent dfce86d3db
commit e1bceada6d
15 changed files with 1060 additions and 786 deletions

101
src/input/auth.rs Normal file
View File

@@ -0,0 +1,101 @@
use crossterm::event::KeyCode;
use std::time::Duration;
use tokio::time::timeout;
use crate::app::App;
use crate::tdlib::client::AuthState;
pub async fn handle(app: &mut App, key_code: KeyCode) {
match &app.td_client.auth_state {
AuthState::WaitPhoneNumber => match key_code {
KeyCode::Char(c) => {
app.phone_input.push(c);
app.error_message = None;
}
KeyCode::Backspace => {
app.phone_input.pop();
app.error_message = None;
}
KeyCode::Enter => {
if !app.phone_input.is_empty() {
app.status_message = Some("Отправка номера...".to_string());
match timeout(Duration::from_secs(10), app.td_client.send_phone_number(app.phone_input.clone())).await {
Ok(Ok(_)) => {
app.error_message = None;
app.status_message = None;
}
Ok(Err(e)) => {
app.error_message = Some(e);
app.status_message = None;
}
Err(_) => {
app.error_message = Some("Таймаут".to_string());
app.status_message = None;
}
}
}
}
_ => {}
},
AuthState::WaitCode => match key_code {
KeyCode::Char(c) if c.is_numeric() => {
app.code_input.push(c);
app.error_message = None;
}
KeyCode::Backspace => {
app.code_input.pop();
app.error_message = None;
}
KeyCode::Enter => {
if !app.code_input.is_empty() {
app.status_message = Some("Проверка кода...".to_string());
match timeout(Duration::from_secs(10), app.td_client.send_code(app.code_input.clone())).await {
Ok(Ok(_)) => {
app.error_message = None;
app.status_message = None;
}
Ok(Err(e)) => {
app.error_message = Some(e);
app.status_message = None;
}
Err(_) => {
app.error_message = Some("Таймаут".to_string());
app.status_message = None;
}
}
}
}
_ => {}
},
AuthState::WaitPassword => match key_code {
KeyCode::Char(c) => {
app.password_input.push(c);
app.error_message = None;
}
KeyCode::Backspace => {
app.password_input.pop();
app.error_message = None;
}
KeyCode::Enter => {
if !app.password_input.is_empty() {
app.status_message = Some("Проверка пароля...".to_string());
match timeout(Duration::from_secs(10), app.td_client.send_password(app.password_input.clone())).await {
Ok(Ok(_)) => {
app.error_message = None;
app.status_message = None;
}
Ok(Err(e)) => {
app.error_message = Some(e);
app.status_message = None;
}
Err(_) => {
app.error_message = Some("Таймаут".to_string());
app.status_message = None;
}
}
}
}
_ => {}
},
_ => {}
}
}