2021-11-03 09:52:02 +00:00
|
|
|
use rocket::{get, request::FlashMessage};
|
2022-01-13 11:16:38 +00:00
|
|
|
use rocket_dyn_templates::{tera::Context, Template};
|
2021-10-28 08:01:31 +00:00
|
|
|
|
2021-11-08 15:38:10 +00:00
|
|
|
use crate::routes::authentication::Authenticated;
|
2022-01-18 10:49:47 +00:00
|
|
|
use crate::STANDALONE_MODE;
|
2021-11-08 15:38:10 +00:00
|
|
|
|
2021-11-03 09:52:02 +00:00
|
|
|
// HELPERS AND ROUTES FOR / (HOME PAGE)
|
2021-10-28 08:01:31 +00:00
|
|
|
|
|
|
|
#[get("/")]
|
2021-11-15 15:32:00 +00:00
|
|
|
pub fn home(_auth: Authenticated) -> Template {
|
2022-01-13 11:16:38 +00:00
|
|
|
let mut context = Context::new();
|
|
|
|
context.insert("flash_name", &None::<()>);
|
|
|
|
context.insert("flash_msg", &None::<()>);
|
|
|
|
context.insert("title", &None::<()>);
|
2022-01-18 10:49:47 +00:00
|
|
|
// pass in mode so we can define appropriate urls in template
|
|
|
|
context.insert("standalone_mode", &*STANDALONE_MODE);
|
2021-10-28 08:01:31 +00:00
|
|
|
|
2022-01-13 11:16:38 +00:00
|
|
|
Template::render("home", &context.into_json())
|
2021-10-28 08:01:31 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 11:16:38 +00:00
|
|
|
// HELPERS AND ROUTES FOR /help
|
2021-10-28 08:01:31 +00:00
|
|
|
|
|
|
|
#[get("/help")]
|
|
|
|
pub fn help(flash: Option<FlashMessage>) -> Template {
|
2022-01-13 11:16:38 +00:00
|
|
|
let mut context = Context::new();
|
|
|
|
context.insert("back", &Some("/".to_string()));
|
|
|
|
context.insert("title", &Some("Help".to_string()));
|
|
|
|
|
2021-10-28 08:01:31 +00:00
|
|
|
// check to see if there is a flash message to display
|
|
|
|
if let Some(flash) = flash {
|
2022-01-13 11:16:38 +00:00
|
|
|
context.insert("flash_name", &Some(flash.kind().to_string()));
|
|
|
|
context.insert("flash_msg", &Some(flash.message().to_string()));
|
2021-10-28 08:01:31 +00:00
|
|
|
};
|
2022-01-13 11:16:38 +00:00
|
|
|
|
2022-01-13 13:48:55 +00:00
|
|
|
Template::render("help", &context.into_json())
|
2021-10-28 08:01:31 +00:00
|
|
|
}
|