open registration toggle
This commit is contained in:
parent
0a827492c0
commit
5e71ee1be6
3 changed files with 17 additions and 1 deletions
|
|
@ -69,6 +69,12 @@ in
|
||||||
description = "Maximum length for website URLs. 0 for unlimited.";
|
description = "Maximum length for website URLs. 0 for unlimited.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
openRegistration = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "Allow new guestbook submissions. When false, the form is hidden and submissions are rejected.";
|
||||||
|
};
|
||||||
|
|
||||||
user = mkOption {
|
user = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "guestbook";
|
default = "guestbook";
|
||||||
|
|
@ -108,6 +114,7 @@ in
|
||||||
BOOK_MAX_NAME_LENGTH = toString cfg.maxNameLength;
|
BOOK_MAX_NAME_LENGTH = toString cfg.maxNameLength;
|
||||||
BOOK_MAX_MESSAGE_LENGTH = toString cfg.maxMessageLength;
|
BOOK_MAX_MESSAGE_LENGTH = toString cfg.maxMessageLength;
|
||||||
BOOK_MAX_WEBSITE_LENGTH = toString cfg.maxWebsiteLength;
|
BOOK_MAX_WEBSITE_LENGTH = toString cfg.maxWebsiteLength;
|
||||||
|
BOOK_OPEN_REGISTRATION = if cfg.openRegistration then "true" else "false";
|
||||||
};
|
};
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ pub struct Config {
|
||||||
pub max_name_length: usize,
|
pub max_name_length: usize,
|
||||||
pub max_message_length: usize,
|
pub max_message_length: usize,
|
||||||
pub max_website_length: usize,
|
pub max_website_length: usize,
|
||||||
|
pub open_registration: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
|
@ -52,6 +53,9 @@ impl Config {
|
||||||
.unwrap_or_else(|_| "100".into())
|
.unwrap_or_else(|_| "100".into())
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| "BOOK_MAX_WEBSITE_LENGTH must be a number")?,
|
.map_err(|_| "BOOK_MAX_WEBSITE_LENGTH must be a number")?,
|
||||||
|
open_registration: env::var("BOOK_OPEN_REGISTRATION")
|
||||||
|
.map(|v| v != "false")
|
||||||
|
.unwrap_or(true),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,12 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||||
async fn index(State(state): State<Arc<AppState>>) -> Html<String> {
|
async fn index(State(state): State<Arc<AppState>>) -> Html<String> {
|
||||||
let entries_dir = state.config.data_dir.join("entries");
|
let entries_dir = state.config.data_dir.join("entries");
|
||||||
let entries = entries::read_approved(&entries_dir);
|
let entries = entries::read_approved(&entries_dir);
|
||||||
|
let form = if state.config.open_registration { FORM_HTML } else { "" };
|
||||||
let html = render::render_page(
|
let html = render::render_page(
|
||||||
&state.config.site_title,
|
&state.config.site_title,
|
||||||
&state.config.site_url,
|
&state.config.site_url,
|
||||||
&entries,
|
&entries,
|
||||||
FORM_HTML,
|
form,
|
||||||
);
|
);
|
||||||
Html(html)
|
Html(html)
|
||||||
}
|
}
|
||||||
|
|
@ -52,6 +53,10 @@ async fn submit(
|
||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
Form(form): Form<SubmitForm>,
|
Form(form): Form<SubmitForm>,
|
||||||
) -> Html<String> {
|
) -> Html<String> {
|
||||||
|
if !state.config.open_registration {
|
||||||
|
return Html("Submissions are closed.".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
// Honeypot check — silently discard
|
// Honeypot check — silently discard
|
||||||
if state.config.honeypot && !form.url.is_empty() {
|
if state.config.honeypot && !form.url.is_empty() {
|
||||||
return Html("Thanks! Your message is pending approval.".to_string());
|
return Html("Thanks! Your message is pending approval.".to_string());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue