add admin menu and config routes; start thinking about flash msgs
This commit is contained in:
parent
580771ebf2
commit
7c98cfcd5d
|
@ -1774,7 +1774,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "kuska-ssb"
|
||||
version = "0.4.0"
|
||||
source = "git+https://github.com/mycognosist/ssb.git?branch=private_messages#4ae3e9ea24b828b9f11cb3af6866e8656924b9d0"
|
||||
source = "git+https://github.com/Kuska-ssb/ssb#fb7062de606e7c9cae8dd4df402a122db46c1b77"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"async-stream 0.2.1",
|
||||
|
|
|
@ -19,9 +19,15 @@ we do not need to be super fast or feature-rich.
|
|||
x template
|
||||
x sbot_config data
|
||||
- might need some thought...render elements or input data
|
||||
- admin
|
||||
x menu
|
||||
- configure
|
||||
- change
|
||||
- reset
|
||||
|
||||
x write the nav and base templates
|
||||
x get the homepage loading properly
|
||||
x route handler
|
||||
x template
|
||||
x file loading (static assets)
|
||||
- write getter, setter and unsetter for flash messages
|
||||
- from rocket docs
|
||||
- A “removal” cookie is a cookie that has the same name as the original cookie but has an empty value, a max-age of 0, and an expiration date far in the past.
|
||||
- use Response::with_additional_header() method to set cookie
|
||||
- https://docs.rs/rouille/latest/rouille/struct.Response.html#method.with_additional_header
|
||||
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
|
||||
|
|
|
@ -140,6 +140,14 @@ fn main() {
|
|||
Response::html(routes::settings::scuttlebutt::configure::build())
|
||||
},
|
||||
|
||||
(GET) (/settings/admin) => {
|
||||
Response::html(routes::settings::admin::menu::build())
|
||||
},
|
||||
|
||||
(GET) (/settings/admin/configure) => {
|
||||
Response::html(routes::settings::admin::configure::build())
|
||||
},
|
||||
|
||||
// The code block is called if none of the other blocks matches the request.
|
||||
// We return an empty response with a 404 status code.
|
||||
_ => Response::empty_404()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
use rocket::{
|
||||
form::{Form, FromForm},
|
||||
get, post,
|
||||
|
@ -120,3 +121,4 @@ pub fn delete_admin_post(
|
|||
),
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -0,0 +1,59 @@
|
|||
use maud::{html, PreEscaped};
|
||||
use peach_lib::config_manager;
|
||||
|
||||
use crate::templates;
|
||||
|
||||
/// Administrator settings menu template builder.
|
||||
pub fn build() -> 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("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(
|
||||
menu_template,
|
||||
"Configure Administrators",
|
||||
Some("/settings/admin"),
|
||||
);
|
||||
|
||||
// render the base template with the provided body
|
||||
templates::base::build(body)
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
use maud::{html, PreEscaped};
|
||||
|
||||
use crate::templates;
|
||||
|
||||
/// Administrator settings menu template builder.
|
||||
pub fn build() -> PreEscaped<String> {
|
||||
let menu_template = html! {
|
||||
(PreEscaped("<!-- ADMIN SETTINGS MENU -->"))
|
||||
div class="card center" {
|
||||
(PreEscaped("<!-- BUTTONS -->"))
|
||||
div id="settingsButtons" {
|
||||
a id="configure" class="button button-primary center" href="/settings/admin/configure" title="Configure Admin" { "Configure Admin" }
|
||||
a id="change" class="button button-primary center" href="/settings/admin/change_password" title="Change Password" { "Change Password" }
|
||||
a id="reset" class="button button-primary center" href="/settings/admin/forgot_password" title="Reset Password" { "Reset Password" }
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// wrap the nav bars around the settings menu template content
|
||||
// parameters are template, title and back url
|
||||
let body = templates::nav::build(menu_template, "Administrator Settings", Some("/settings"));
|
||||
|
||||
// render the base template with the provided body
|
||||
templates::base::build(body)
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
pub mod configure;
|
||||
pub mod menu;
|
|
@ -1,4 +1,4 @@
|
|||
//pub mod admin;
|
||||
pub mod admin;
|
||||
//pub mod dns;
|
||||
pub mod menu;
|
||||
//pub mod network;
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
use maud::{html, Markup};
|
||||
|
||||
/// Flash message template builder.
|
||||
///
|
||||
/// Render a flash elements based on the given flash name and message.
|
||||
pub fn build(flash_name: &str, flash_msg: &str) -> Markup {
|
||||
let flash_class = match flash_name {
|
||||
"success" => "capsule center-text flash-message font-normal border-success",
|
||||
"info" => "capsule center-text flash-message font-normal border-info",
|
||||
"warning" => "capsule center-text flash-message font-normal border-warning",
|
||||
"error" => "capsule center-text flash-message font-normal border-danger",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
html! {
|
||||
div class=(flash_class) {
|
||||
(flash_msg)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
pub mod base;
|
||||
pub mod flash;
|
||||
pub mod nav;
|
||||
|
|
|
@ -24,6 +24,10 @@ pub fn set_theme(theme: Theme) {
|
|||
*writable_theme = theme;
|
||||
}
|
||||
|
||||
// get_cookie
|
||||
|
||||
// set_cookie
|
||||
|
||||
/*
|
||||
pub mod monitor;
|
||||
|
||||
|
|
Loading…
Reference in New Issue