47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
use snafu::prelude::*;
|
|
use yunohost_api::{Password, Username, YunohostPermissions, YunohostUsers};
|
|
|
|
use std::sync::Arc;
|
|
|
|
use crate::error::*;
|
|
|
|
pub mod login;
|
|
pub use login::LoggedInUser;
|
|
pub mod logout;
|
|
pub use logout::LoggedOutUser;
|
|
pub mod sessions;
|
|
pub use sessions::{Session, SessionManager};
|
|
|
|
pub type RoutableAppState = Arc<AppState>;
|
|
|
|
pub const COOKIE_NAME: &'static str = "yunohost.ssowat";
|
|
|
|
pub struct AppState {
|
|
pub sessions: SessionManager,
|
|
pub users: YunohostUsers,
|
|
pub permissions: YunohostPermissions,
|
|
}
|
|
|
|
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)?,
|
|
// TODO: make async
|
|
permissions: YunohostPermissions::new().context(YunohostSnafu)?,
|
|
})
|
|
}
|
|
|
|
pub async fn check_login(
|
|
&self,
|
|
username: &Username,
|
|
password: &Password,
|
|
) -> Result<bool, Error> {
|
|
self.users
|
|
.check_credentials(username, password)
|
|
.await
|
|
.context(YunohostSnafu)
|
|
}
|
|
}
|