80 lines
3.7 KiB
Rust
80 lines
3.7 KiB
Rust
use maud::{html, PreEscaped};
|
|
use peach_lib::config_manager;
|
|
use rouille::Request;
|
|
|
|
use crate::{
|
|
templates,
|
|
utils::{flash::FlashRequest, theme},
|
|
};
|
|
|
|
/// Administrator settings menu template builder.
|
|
pub fn build_template(request: &Request) -> PreEscaped<String> {
|
|
// check for flash cookies; will be (None, None) if no flash cookies are found
|
|
let (mut flash_name, mut flash_msg) = request.retrieve_flash();
|
|
|
|
// attempt to load peachcloud config file
|
|
let ssb_admins = match config_manager::load_peach_config() {
|
|
Ok(config) => Some(config.ssb_admin_ids),
|
|
// note: this will overwrite any received flash cookie values
|
|
// TODO: find a way to include the `err` in the flash_msg
|
|
// currently produces an error because we end up with Some(String)
|
|
// instead of Some(str)
|
|
Err(_err) => {
|
|
flash_name = Some("flash_name=error");
|
|
flash_msg = Some("flash_msg=Failed to read PeachCloud configuration file");
|
|
None
|
|
}
|
|
};
|
|
|
|
let menu_template = html! {
|
|
(PreEscaped("<!-- CONFIGURE ADMIN PAGE -->"))
|
|
div class="card center" {
|
|
div class="capsule capsule-profile center-text font-normal border-info" style="font-family: var(--sans-serif); font-size: var(--font-size-6); margin-bottom: 1.5rem;" {
|
|
"Administrators are identified and added by their Scuttlebutt public keys. These accounts will be sent private messages on Scuttlebutt when a password reset is requested."
|
|
}
|
|
@if let Some(ref ssb_admin_ids) = ssb_admins {
|
|
@for admin in ssb_admin_ids {
|
|
form class="center" action="/settings/admin/delete" method="post" {
|
|
div class="center" style="display: flex; justify-content: space-between;" {
|
|
input type="hidden" name="ssb_id" value=(admin);
|
|
p class="label-small label-ellipsis font-gray" style="user-select: all;" { (admin) }
|
|
input style="width: 30%;" type="submit" class="button button-warning" value="Delete" title="Delete SSB administrator";
|
|
}
|
|
}
|
|
}
|
|
} @else {
|
|
div class="card-text" {
|
|
"There are no currently configured admins."
|
|
}
|
|
}
|
|
form id="addAdmin" class="center" style="margin-top: 2rem;" action="/settings/admin/add" method="post" {
|
|
div class="center" style="display: flex; flex-direction: column; margin-bottom: 2rem;" title="Public key (ID) of a desired administrator" {
|
|
label for="publicKey" class="label-small font-gray" { "PUBLIC KEY" }
|
|
input type="text" id="publicKey" name="ssb_id" placeholder="@xYz...=.ed25519" autofocus;
|
|
}
|
|
(PreEscaped("<!-- BUTTONS -->"))
|
|
input class="button button-primary center" type="submit" title="Add SSB administrator" value="Add Admin";
|
|
}
|
|
// render flash message if cookies were found in the request
|
|
@if let (Some(name), Some(msg)) = (flash_name, flash_msg) {
|
|
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
|
(templates::flash::build_template(name, msg))
|
|
}
|
|
}
|
|
};
|
|
|
|
// wrap the nav bars around the settings menu template content
|
|
// parameters are template, title and back url
|
|
let body = templates::nav::build_template(
|
|
menu_template,
|
|
"Configure Administrators",
|
|
Some("/settings/admin"),
|
|
);
|
|
|
|
// query the current theme so we can pass it into the base template builder
|
|
let theme = theme::get_theme();
|
|
|
|
// render the base template with the provided body
|
|
templates::base::build_template(body, theme)
|
|
}
|