use snafu::prelude::*; use yunohost_api::{YunohostUsers, Username, Password}; use std::sync::Arc; use crate::error::*; pub mod sessions; use sessions::SessionManager; pub type RoutableAppState = Arc; pub const COOKIE_NAME: &'static str = "yunohost.ssowat"; pub struct AppState { pub sessions: SessionManager, pub users: YunohostUsers, } impl AppState { pub async fn new() -> Result { Ok(AppState { sessions: SessionManager::new().context(SessionSnafu)?, // Timeout in ms users: YunohostUsers::new(500).await.context(YunohostSnafu)?, }) } pub async fn check_login(&self, username: &Username, password: &Password) -> Result { self.users.check_credentials(username, password).await.context(YunohostSnafu) } }