2022-01-26 09:45:59 +00:00
|
|
|
use rocket::{get, request::FlashMessage, State};
|
2022-01-13 11:16:38 +00:00
|
|
|
use rocket_dyn_templates::{tera::Context, Template};
|
2021-11-15 15:32:00 +00:00
|
|
|
|
|
|
|
use crate::routes::authentication::Authenticated;
|
2022-02-03 14:29:20 +00:00
|
|
|
use crate::utils;
|
2022-01-26 09:45:59 +00:00
|
|
|
use crate::RocketConfig;
|
2021-11-15 15:32:00 +00:00
|
|
|
|
|
|
|
// HELPERS AND ROUTES FOR /settings
|
|
|
|
|
|
|
|
/// View and delete currently configured admin.
|
|
|
|
#[get("/settings")]
|
2022-01-26 09:45:59 +00:00
|
|
|
pub fn settings_menu(
|
|
|
|
_auth: Authenticated,
|
|
|
|
flash: Option<FlashMessage>,
|
|
|
|
config: &State<RocketConfig>,
|
|
|
|
) -> Template {
|
2022-02-03 14:29:20 +00:00
|
|
|
// retrieve current ui theme
|
|
|
|
let theme = utils::get_theme();
|
|
|
|
|
2022-01-13 11:16:38 +00:00
|
|
|
let mut context = Context::new();
|
2022-02-03 14:29:20 +00:00
|
|
|
context.insert("theme", &theme);
|
2022-01-13 11:16:38 +00:00
|
|
|
context.insert("back", &Some("/".to_string()));
|
|
|
|
context.insert("title", &Some("Settings".to_string()));
|
|
|
|
|
2022-01-26 09:45:59 +00:00
|
|
|
// pass in mode from managed state so we can conditionally render html elements
|
|
|
|
context.insert("standalone_mode", &config.standalone_mode);
|
|
|
|
|
2021-11-15 15:32:00 +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-11-15 15:32:00 +00:00
|
|
|
};
|
2022-01-13 11:16:38 +00:00
|
|
|
|
|
|
|
Template::render("settings/menu", &context.into_json())
|
2021-11-15 15:32:00 +00:00
|
|
|
}
|