Admin only routes
This commit is contained in:
parent
799298ca34
commit
64dd81e941
@ -168,6 +168,7 @@ pub async fn initialize(
|
||||
routes::dashboard::export::import_todos,
|
||||
],
|
||||
)
|
||||
.mount("/admin", routes![routes::admin::admin_dashboard_home])
|
||||
.launch()
|
||||
.await?;
|
||||
|
||||
|
21
web/src/routes/admin.rs
Normal file
21
web/src/routes/admin.rs
Normal 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)
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod admin;
|
||||
pub mod dashboard;
|
||||
pub mod login;
|
||||
pub mod report;
|
||||
|
9
web/templates/admin_dashboard.html.tera
Normal file
9
web/templates/admin_dashboard.html.tera
Normal file
@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="EN">
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user