peach-workspace/peach-web/src/routes/index.rs

38 lines
1.2 KiB
Rust

use rocket::{get, request::FlashMessage, State};
use rocket_dyn_templates::{tera::Context, Template};
use crate::routes::authentication::Authenticated;
use crate::RocketConfig;
// HELPERS AND ROUTES FOR / (HOME PAGE)
#[get("/")]
pub fn home(_auth: Authenticated, config: &State<RocketConfig>) -> Template {
let mut context = Context::new();
context.insert("flash_name", &None::<()>);
context.insert("flash_msg", &None::<()>);
context.insert("title", &None::<()>);
// pass in mode from managed state so we can define appropriate urls in template
context.insert("standalone_mode", &config.standalone_mode);
Template::render("home", &context.into_json())
}
// HELPERS AND ROUTES FOR /help
#[get("/help")]
pub fn help(flash: Option<FlashMessage>) -> Template {
let mut context = Context::new();
context.insert("back", &Some("/".to_string()));
context.insert("title", &Some("Help".to_string()));
// check to see if there is a flash message to display
if let Some(flash) = flash {
context.insert("flash_name", &Some(flash.kind().to_string()));
context.insert("flash_msg", &Some(flash.message().to_string()));
};
Template::render("help", &context.into_json())
}