feat: Add ListUsers operation

This commit is contained in:
selfhoster selfhoster 2026-09-08 16:39:50 +02:00
commit dba07912d2
9 changed files with 166 additions and 28 deletions

View file

@ -3,6 +3,8 @@ use uuid::Uuid;
use std::sync::{Arc, RwLock};
use crate::db::User;
pub const COOKIE_NAME: &str = "lldap_session";
#[derive(Clone, Debug)]
@ -17,17 +19,13 @@ impl HttpSessionManager {
}
}
pub fn add_session(&self, username: &str, is_admin: bool, cookies: CookieJar) -> CookieJar {
pub fn add_session(&self, user: User, cookies: CookieJar) -> CookieJar {
let uuid = Uuid::new_v4();
let mut cookie = Cookie::new(COOKIE_NAME, uuid.to_string());
cookie.set_path("/");
let session = HttpSession {
username: username.to_string(),
is_admin,
uuid,
};
let session = HttpSession { user, uuid };
{
self.inner.write().unwrap().push(session);
@ -67,9 +65,16 @@ impl HttpSessionManager {
}
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug)]
pub struct HttpSession {
pub username: String,
pub is_admin: bool,
// TODO: by storing the session here, it means
// it needs to be updated every time we change the user.
pub user: User,
pub uuid: Uuid,
}
impl PartialEq<HttpSession> for HttpSession {
fn eq(&self, other: &Self) -> bool {
self.uuid == other.uuid
}
}