60 lines
2.9 KiB
Rust
60 lines
2.9 KiB
Rust
use maud::{html, PreEscaped};
|
|
use peach_lib::config_manager;
|
|
|
|
use crate::templates;
|
|
|
|
/// Administrator settings menu template builder.
|
|
pub fn build_template() -> PreEscaped<String> {
|
|
// attempt to load peachcloud config file
|
|
let ssb_admins = config_manager::load_peach_config()
|
|
.ok()
|
|
.map(|config| config.ssb_admin_ids);
|
|
|
|
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";
|
|
(PreEscaped("<!-- FLASH MESSAGE -->"))
|
|
@if ssb_admins.is_none() {
|
|
(templates::flash::build_template("error", "Failed to read PeachCloud configuration file"))
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
// 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"),
|
|
);
|
|
|
|
// render the base template with the provided body
|
|
templates::base::build_template(body)
|
|
}
|