42 lines
1.3 KiB
Rust
42 lines
1.3 KiB
Rust
use rocket::{get, request::FlashMessage, serde::Serialize};
|
|
use rocket_dyn_templates::Template;
|
|
|
|
use crate::routes::authentication::Authenticated;
|
|
|
|
// HELPERS AND ROUTES FOR /settings
|
|
|
|
#[derive(Debug, Serialize)]
|
|
pub struct SettingsMenuContext {
|
|
pub back: Option<String>,
|
|
pub title: Option<String>,
|
|
pub flash_name: Option<String>,
|
|
pub flash_msg: Option<String>,
|
|
}
|
|
|
|
impl SettingsMenuContext {
|
|
pub fn build() -> SettingsMenuContext {
|
|
SettingsMenuContext {
|
|
back: None,
|
|
title: None,
|
|
flash_name: None,
|
|
flash_msg: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// View and delete currently configured admin.
|
|
#[get("/settings")]
|
|
pub fn settings_menu(flash: Option<FlashMessage>, _auth: Authenticated) -> Template {
|
|
let mut context = SettingsMenuContext::build();
|
|
// set back icon link to network route
|
|
context.back = Some("/".to_string());
|
|
context.title = Some("Settings".to_string());
|
|
// check to see if there is a flash message to display
|
|
if let Some(flash) = flash {
|
|
// add flash message contents to the context object
|
|
context.flash_name = Some(flash.kind().to_string());
|
|
context.flash_msg = Some(flash.message().to_string());
|
|
};
|
|
Template::render("settings/menu", &context)
|
|
}
|