peach-workspace/peach-web/src/routes/settings/admin/delete.rs

37 lines
1.2 KiB
Rust

use peach_lib::config_manager;
use rouille::{post_input, try_or_400, Request, Response};
// HELPERS AND ROUTES FOR /settings/admin/delete
/// Parse an `admin_id` from the submitted form, delete it from file
/// (`/var/lib/peachcloud/config.yml`) and redirect to the administrator
/// configuration URL.
pub fn handle_form(request: &Request) -> Response {
// query the request body for form data
// return a 400 error if the admin_id field is missing
let data = try_or_400!(post_input!(request, {
// the public key of a desired administrator
ssb_id: String,
}));
// remove submitted admin id from file
let _result = config_manager::delete_ssb_admin_id(&data.ssb_id);
// TODO: match on result and define flash message accordingly
// then send the redirect response
// redirect to the configure admin page
// TODO: add flash message
Response::redirect_303("/settings/admin/configure")
}
/*
match result {
Ok(_) => Flash::success(Redirect::to(url), "Removed SSB administrator"),
Err(e) => Flash::error(
Redirect::to(url),
format!("Failed to remove admin id: {}", e),
),
}
*/