diff --git a/Cargo.lock b/Cargo.lock index 6320894..d8c939c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/peach-web/rouille_refactor b/peach-web/rouille_refactor index 1fcf234..8d71a21 100644 --- a/peach-web/rouille_refactor +++ b/peach-web/rouille_refactor @@ -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 diff --git a/peach-web/src/main.rs b/peach-web/src/main.rs index 9ca6149..e1ba8dd 100644 --- a/peach-web/src/main.rs +++ b/peach-web/src/main.rs @@ -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() diff --git a/peach-web/src/routes/settings/admin.rs b/peach-web/src/routes/settings/admin.rs_old similarity index 99% rename from peach-web/src/routes/settings/admin.rs rename to peach-web/src/routes/settings/admin.rs_old index 89b296f..c5d437a 100644 --- a/peach-web/src/routes/settings/admin.rs +++ b/peach-web/src/routes/settings/admin.rs_old @@ -1,3 +1,4 @@ +/* use rocket::{ form::{Form, FromForm}, get, post, @@ -120,3 +121,4 @@ pub fn delete_admin_post( ), } } +*/ diff --git a/peach-web/src/routes/settings/admin/configure.rs b/peach-web/src/routes/settings/admin/configure.rs new file mode 100644 index 0000000..d0f7329 --- /dev/null +++ b/peach-web/src/routes/settings/admin/configure.rs @@ -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 { + // 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("")) + 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("")) + input class="button button-primary center" type="submit" title="Add SSB administrator" value="Add Admin"; + (PreEscaped("")) + @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) +} diff --git a/peach-web/src/routes/settings/admin/menu.rs b/peach-web/src/routes/settings/admin/menu.rs new file mode 100644 index 0000000..24f57b3 --- /dev/null +++ b/peach-web/src/routes/settings/admin/menu.rs @@ -0,0 +1,26 @@ +use maud::{html, PreEscaped}; + +use crate::templates; + +/// Administrator settings menu template builder. +pub fn build() -> PreEscaped { + let menu_template = html! { + (PreEscaped("")) + div class="card center" { + (PreEscaped("")) + 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) +} diff --git a/peach-web/src/routes/settings/admin/mod.rs b/peach-web/src/routes/settings/admin/mod.rs new file mode 100644 index 0000000..485da58 --- /dev/null +++ b/peach-web/src/routes/settings/admin/mod.rs @@ -0,0 +1,2 @@ +pub mod configure; +pub mod menu; diff --git a/peach-web/src/routes/settings/mod.rs b/peach-web/src/routes/settings/mod.rs index 0b2a088..2088ee3 100644 --- a/peach-web/src/routes/settings/mod.rs +++ b/peach-web/src/routes/settings/mod.rs @@ -1,4 +1,4 @@ -//pub mod admin; +pub mod admin; //pub mod dns; pub mod menu; //pub mod network; diff --git a/peach-web/src/templates/flash.rs b/peach-web/src/templates/flash.rs new file mode 100644 index 0000000..1a4c08e --- /dev/null +++ b/peach-web/src/templates/flash.rs @@ -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) + } + } +} diff --git a/peach-web/src/templates/mod.rs b/peach-web/src/templates/mod.rs index 137668d..30ac0ee 100644 --- a/peach-web/src/templates/mod.rs +++ b/peach-web/src/templates/mod.rs @@ -1,2 +1,3 @@ pub mod base; +pub mod flash; pub mod nav; diff --git a/peach-web/src/utils.rs b/peach-web/src/utils.rs index fc63575..9f99492 100644 --- a/peach-web/src/utils.rs +++ b/peach-web/src/utils.rs @@ -24,6 +24,10 @@ pub fn set_theme(theme: Theme) { *writable_theme = theme; } +// get_cookie + +// set_cookie + /* pub mod monitor;