use async_trait::async_trait; use gamenight_api_client_rs::{apis::{configuration::Configuration, default_api::get_token}, models}; use inquire::{Password, Text}; use super::*; #[derive(Clone)] pub struct Login { } impl Login { pub fn new() -> Self { Self {} } } #[async_trait] impl<'a> Flow<'a> for Login { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { let configuration = Configuration::new(); let username = Text::new("What is your login?").prompt()?; let password = Password::new("what is your password?") .without_confirmation() .prompt()?; let login = models::Login::new(username, password); let result = get_token(&configuration, Some(login)).await?; clear_screen::clear(); if let Some(token) = result.jwt_token { state.api_configuration.bearer_access_token = Some(token); Ok((FlowOutcome::Successful, state)) } else { Err(FlowError{error: "Unexpected response".to_string()}) } } } impl Display for Login { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "Login") } }