diff --git a/web/src/lib.rs b/web/src/lib.rs index c3df67a..0486cb3 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -168,6 +168,7 @@ pub async fn initialize( routes::dashboard::export::import_todos, ], ) + .mount("/admin", routes![routes::admin::admin_dashboard_home]) .launch() .await?; diff --git a/web/src/routes/admin.rs b/web/src/routes/admin.rs new file mode 100644 index 0000000..473d30d --- /dev/null +++ b/web/src/routes/admin.rs @@ -0,0 +1,21 @@ +use std::{collections::HashMap, env}; + +use rocket::{ + http::{CookieJar, Status}, + serde::json::{json, Json}, +}; +use rocket_dyn_templates::Template; + +#[get("/")] +pub async fn admin_dashboard_home(cookies: &CookieJar<'_>) -> Result { + if let Some(cookie) = cookies.get_private("userid") { + let map: HashMap<&str, String> = HashMap::new(); + if Some(cookie.value().to_string()) == env::var("ADMIN_ID").ok() { + Ok(Template::render("admin_dashboard", &map)) + } else { + Err(Status::Forbidden) + } + } else { + Err(Status::Unauthorized) + } +} diff --git a/web/src/routes/mod.rs b/web/src/routes/mod.rs index 895be9e..b9c871e 100644 --- a/web/src/routes/mod.rs +++ b/web/src/routes/mod.rs @@ -1,3 +1,4 @@ +pub mod admin; pub mod dashboard; pub mod login; pub mod report; diff --git a/web/templates/admin_dashboard.html.tera b/web/templates/admin_dashboard.html.tera new file mode 100644 index 0000000..b74f2e1 --- /dev/null +++ b/web/templates/admin_dashboard.html.tera @@ -0,0 +1,9 @@ + + + + + + + + +