open registration toggle

This commit is contained in:
Lewis Wynne 2026-04-09 14:56:40 +01:00
parent 0a827492c0
commit 5e71ee1be6
3 changed files with 17 additions and 1 deletions

View file

@ -13,6 +13,7 @@ pub struct Config {
pub max_name_length: usize,
pub max_message_length: usize,
pub max_website_length: usize,
pub open_registration: bool,
}
impl Config {
@ -52,6 +53,9 @@ impl Config {
.unwrap_or_else(|_| "100".into())
.parse()
.map_err(|_| "BOOK_MAX_WEBSITE_LENGTH must be a number")?,
open_registration: env::var("BOOK_OPEN_REGISTRATION")
.map(|v| v != "false")
.unwrap_or(true),
})
}
}

View file

@ -39,11 +39,12 @@ pub fn router(state: Arc<AppState>) -> Router {
async fn index(State(state): State<Arc<AppState>>) -> Html<String> {
let entries_dir = state.config.data_dir.join("entries");
let entries = entries::read_approved(&entries_dir);
let form = if state.config.open_registration { FORM_HTML } else { "" };
let html = render::render_page(
&state.config.site_title,
&state.config.site_url,
&entries,
FORM_HTML,
form,
);
Html(html)
}
@ -52,6 +53,10 @@ async fn submit(
State(state): State<Arc<AppState>>,
Form(form): Form<SubmitForm>,
) -> Html<String> {
if !state.config.open_registration {
return Html("Submissions are closed.".to_string());
}
// Honeypot check — silently discard
if state.config.honeypot && !form.url.is_empty() {
return Html("Thanks! Your message is pending approval.".to_string());