Files
telegram-tui/src/input/auth.rs
Mikhail Kilin 264f183510
Some checks failed
ci/woodpecker/pr/check Pipeline failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
style: auto-format entire codebase with cargo fmt (stable rustfmt.toml)
2026-02-22 17:09:51 +03:00

110 lines
4.1 KiB
Rust

use crate::app::App;
use crate::tdlib::{AuthState, TdClientTrait};
use crate::utils::{is_non_empty, with_timeout_msg};
use crossterm::event::KeyCode;
use std::time::Duration;
pub async fn handle<T: TdClientTrait>(app: &mut App<T>, key_code: KeyCode) {
match &app.td_client.auth_state() {
AuthState::WaitPhoneNumber => match key_code {
KeyCode::Char(c) => {
app.phone_input_mut().push(c);
app.error_message = None;
}
KeyCode::Backspace => {
app.phone_input_mut().pop();
app.error_message = None;
}
KeyCode::Enter => {
if is_non_empty(app.phone_input()) {
app.status_message = Some("Отправка номера...".to_string());
match with_timeout_msg(
Duration::from_secs(10),
app.td_client
.send_phone_number(app.phone_input().to_string()),
"Таймаут отправки номера",
)
.await
{
Ok(_) => {
app.error_message = None;
app.status_message = None;
}
Err(e) => {
app.error_message = Some(e);
app.status_message = None;
}
}
}
}
_ => {}
},
AuthState::WaitCode => match key_code {
KeyCode::Char(c) if c.is_numeric() => {
app.code_input_mut().push(c);
app.error_message = None;
}
KeyCode::Backspace => {
app.code_input_mut().pop();
app.error_message = None;
}
KeyCode::Enter => {
if is_non_empty(app.code_input()) {
app.status_message = Some("Проверка кода...".to_string());
match with_timeout_msg(
Duration::from_secs(10),
app.td_client.send_code(app.code_input().to_string()),
"Таймаут проверки кода",
)
.await
{
Ok(_) => {
app.error_message = None;
app.status_message = None;
}
Err(e) => {
app.error_message = Some(e);
app.status_message = None;
}
}
}
}
_ => {}
},
AuthState::WaitPassword => match key_code {
KeyCode::Char(c) => {
app.password_input_mut().push(c);
app.error_message = None;
}
KeyCode::Backspace => {
app.password_input_mut().pop();
app.error_message = None;
}
KeyCode::Enter => {
if is_non_empty(app.password_input()) {
app.status_message = Some("Проверка пароля...".to_string());
match with_timeout_msg(
Duration::from_secs(10),
app.td_client
.send_password(app.password_input().to_string()),
"Таймаут проверки пароля",
)
.await
{
Ok(_) => {
app.error_message = None;
app.status_message = None;
}
Err(e) => {
app.error_message = Some(e);
app.status_message = None;
}
}
}
}
_ => {}
},
_ => {}
}
}