From ac631627ab2051a7ad36e97615f4343d4e2cf37d Mon Sep 17 00:00:00 2001 From: Bat Date: Mon, 3 Sep 2018 17:05:45 +0100 Subject: [PATCH] Make it possible to disable registrations Fix #41 --- po/de.po | 4 ++++ po/en.po | 4 ++++ po/fr.po | 4 ++++ po/gl.po | 4 ++++ po/nb.po | 4 ++++ po/pl.po | 4 ++++ po/plume.pot | 3 +++ src/routes/user.rs | 5 +++++ templates/users/new.html.tera | 20 ++++++++++++-------- 9 files changed, 44 insertions(+), 8 deletions(-) diff --git a/po/de.po b/po/de.po index ea8e51b1..e177a94a 100644 --- a/po/de.po +++ b/po/de.po @@ -504,5 +504,9 @@ msgstr "" msgid "Send" msgstr "" +msgid "" +"Sorry, but registrations are closed on this instance. Try to find another one" +msgstr "" + #~ msgid "Your password should be at least 8 characters long" #~ msgstr "Das Passwort sollte mindestens 8 Zeichen lang sein" diff --git a/po/en.po b/po/en.po index 58a9a13d..deccf96e 100644 --- a/po/en.po +++ b/po/en.po @@ -493,3 +493,7 @@ msgstr "" msgid "Send" msgstr "" + +msgid "" +"Sorry, but registrations are closed on this instance. Try to find another one" +msgstr "" diff --git a/po/fr.po b/po/fr.po index 48b37285..e1f3d757 100644 --- a/po/fr.po +++ b/po/fr.po @@ -500,3 +500,7 @@ msgstr "Fichier" msgid "Send" msgstr "Envoyer" + +msgid "" +"Sorry, but registrations are closed on this instance. Try to find another one" +msgstr "Désolé, mais les inscriptions sont fermées sur cette instance. Essayez d'en trouver une autre." diff --git a/po/gl.po b/po/gl.po index b7006e78..1eeb3979 100644 --- a/po/gl.po +++ b/po/gl.po @@ -499,3 +499,7 @@ msgstr "" msgid "Send" msgstr "" + +msgid "" +"Sorry, but registrations are closed on this instance. Try to find another one" +msgstr "" diff --git a/po/nb.po b/po/nb.po index ffdc79aa..275ac691 100644 --- a/po/nb.po +++ b/po/nb.po @@ -508,6 +508,10 @@ msgstr "" msgid "Send" msgstr "" +msgid "" +"Sorry, but registrations are closed on this instance. Try to find another one" +msgstr "" + #~ msgid "One reshare" #~ msgid_plural "{{ count }} reshares" #~ msgstr[0] "Én deling" diff --git a/po/pl.po b/po/pl.po index 2cd35ecd..0b879eca 100644 --- a/po/pl.po +++ b/po/pl.po @@ -519,6 +519,10 @@ msgstr "" msgid "Send" msgstr "" +msgid "" +"Sorry, but registrations are closed on this instance. Try to find another one" +msgstr "" + #~ msgid "One reshare" #~ msgid_plural "{{ count }} reshares" #~ msgstr[0] "Jedno udostępnienie" diff --git a/po/plume.pot b/po/plume.pot index dc78b71e..ca6c8851 100644 --- a/po/plume.pot +++ b/po/plume.pot @@ -483,3 +483,6 @@ msgstr "" msgid "Send" msgstr "" + +msgid "Sorry, but registrations are closed on this instance. Try to find another one" +msgstr "" diff --git a/src/routes/user.rs b/src/routes/user.rs index 451dfb4c..f4982fff 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -166,6 +166,7 @@ fn activity_details(name: String, conn: DbConn, _ap: ApRequest) -> ActivityStrea #[get("/users/new")] fn new(user: Option, conn: DbConn) -> Template { Template::render("users/new", json!({ + "enabled": Instance::get_local(&*conn).map(|i| i.open_registrations).unwrap_or(true), "account": user.map(|u| u.to_json(&*conn)), "errors": null, "form": null @@ -228,6 +229,10 @@ fn passwords_match(form: &NewUserForm) -> Result<(), ValidationError> { #[post("/users/new", data = "")] fn create(conn: DbConn, data: LenientForm) -> Result { + if !Instance::get_local(&*conn).map(|i| i.open_registrations).unwrap_or(true) { + return Ok(Redirect::to(uri!(new))); // Actually, it is an error + } + let form = data.get(); form.validate() .map(|_| { diff --git a/templates/users/new.html.tera b/templates/users/new.html.tera index b0aef4e1..f96aea9b 100644 --- a/templates/users/new.html.tera +++ b/templates/users/new.html.tera @@ -6,13 +6,17 @@ {% endblock title %} {% block content %} -

{{ "Create an account" | _ }}

-
- {{ macros::input(name="username", label="Username", errors=errors, form=form, props='minlenght="1"') }} - {{ macros::input(name="email", label="Email", errors=errors, form=form, type="email") }} - {{ macros::input(name="password", label="Password", errors=errors, form=form, type="password", props='minlenght="8"') }} - {{ macros::input(name="password_confirmation", label="Password confirmation", errors=errors, form=form, type="password", props='minlenght="8"') }} + {% if enabled %} +

{{ "Create an account" | _ }}

+ + {{ macros::input(name="username", label="Username", errors=errors, form=form, props='minlenght="1"') }} + {{ macros::input(name="email", label="Email", errors=errors, form=form, type="email") }} + {{ macros::input(name="password", label="Password", errors=errors, form=form, type="password", props='minlenght="8"') }} + {{ macros::input(name="password_confirmation", label="Password confirmation", errors=errors, form=form, type="password", props='minlenght="8"') }} - -
+ + + {% else %} +

{{ "Sorry, but registrations are closed on this instance. Try to find another one" | _ }}

+ {% endif %} {% endblock content %}