33 lines
838 B
Rust

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<AppState>;
pub const COOKIE_NAME: &'static str = "yunohost.ssowat";
pub struct AppState {
pub sessions: SessionManager,
pub users: YunohostUsers,
}
impl AppState {
pub async fn new() -> Result<AppState, Error> {
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<bool, Error> {
self.users.check_credentials(username, password).await.context(YunohostSnafu)
}
}