add admin menu and config routes; start thinking about flash msgs
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1774,7 +1774,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "kuska-ssb"
|
name = "kuska-ssb"
|
||||||
version = "0.4.0"
|
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 = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-stream 0.2.1",
|
"async-stream 0.2.1",
|
||||||
|
@ -19,9 +19,15 @@ we do not need to be super fast or feature-rich.
|
|||||||
x template
|
x template
|
||||||
x sbot_config data
|
x sbot_config data
|
||||||
- might need some thought...render elements or input data
|
- might need some thought...render elements or input data
|
||||||
|
- admin
|
||||||
|
x menu
|
||||||
|
- configure
|
||||||
|
- change
|
||||||
|
- reset
|
||||||
|
|
||||||
x write the nav and base templates
|
- write getter, setter and unsetter for flash messages
|
||||||
x get the homepage loading properly
|
- from rocket docs
|
||||||
x route handler
|
- 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.
|
||||||
x template
|
- use Response::with_additional_header() method to set cookie
|
||||||
x file loading (static assets)
|
- 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())
|
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.
|
// The code block is called if none of the other blocks matches the request.
|
||||||
// We return an empty response with a 404 status code.
|
// We return an empty response with a 404 status code.
|
||||||
_ => Response::empty_404()
|
_ => Response::empty_404()
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/*
|
||||||
use rocket::{
|
use rocket::{
|
||||||
form::{Form, FromForm},
|
form::{Form, FromForm},
|
||||||
get, post,
|
get, post,
|
||||||
@ -120,3 +121,4 @@ pub fn delete_admin_post(
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
59
peach-web/src/routes/settings/admin/configure.rs
Normal file
59
peach-web/src/routes/settings/admin/configure.rs
Normal file
@ -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)
|
||||||
|
}
|
26
peach-web/src/routes/settings/admin/menu.rs
Normal file
26
peach-web/src/routes/settings/admin/menu.rs
Normal file
@ -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)
|
||||||
|
}
|
2
peach-web/src/routes/settings/admin/mod.rs
Normal file
2
peach-web/src/routes/settings/admin/mod.rs
Normal file
@ -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 dns;
|
||||||
pub mod menu;
|
pub mod menu;
|
||||||
//pub mod network;
|
//pub mod network;
|
||||||
|
20
peach-web/src/templates/flash.rs
Normal file
20
peach-web/src/templates/flash.rs
Normal file
@ -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 base;
|
||||||
|
pub mod flash;
|
||||||
pub mod nav;
|
pub mod nav;
|
||||||
|
@ -24,6 +24,10 @@ pub fn set_theme(theme: Theme) {
|
|||||||
*writable_theme = theme;
|
*writable_theme = theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get_cookie
|
||||||
|
|
||||||
|
// set_cookie
|
||||||
|
|
||||||
/*
|
/*
|
||||||
pub mod monitor;
|
pub mod monitor;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user