Admin only routes

This commit is contained in:
jude 2023-06-21 10:54:20 +01:00
parent 799298ca34
commit 64dd81e941
4 changed files with 32 additions and 0 deletions

View File

@ -168,6 +168,7 @@ pub async fn initialize(
routes::dashboard::export::import_todos, routes::dashboard::export::import_todos,
], ],
) )
.mount("/admin", routes![routes::admin::admin_dashboard_home])
.launch() .launch()
.await?; .await?;

21
web/src/routes/admin.rs Normal file
View File

@ -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<Template, Status> {
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)
}
}

View File

@ -1,3 +1,4 @@
pub mod admin;
pub mod dashboard; pub mod dashboard;
pub mod login; pub mod login;
pub mod report; pub mod report;

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="EN">
<head>
</head>
<body>
</body>
</html>