From 3ef4e1f6b7798f3da3384d34fb0a4a95b91eb9ad Mon Sep 17 00:00:00 2001 From: kaiyou Date: Wed, 11 Apr 2018 21:08:44 +0200 Subject: [PATCH] Add support for recaptcha upon signup --- core/admin/mailu/__init__.py | 2 ++ core/admin/mailu/ui/forms.py | 1 + core/admin/mailu/ui/templates/user/signup.html | 1 + docs/compose/.env | 4 ++++ 4 files changed, 8 insertions(+) diff --git a/core/admin/mailu/__init__.py b/core/admin/mailu/__init__.py index ef98cf9e..e32d2e7d 100644 --- a/core/admin/mailu/__init__.py +++ b/core/admin/mailu/__init__.py @@ -52,6 +52,8 @@ default_config = { 'WEBSITE': 'https://mailu.io', 'WEB_ADMIN': '/admin', 'WEB_WEBMAIL': '/webmail', + 'RECAPTCHA_PUBLIC_KEY': '', + 'RECAPTCHA_PRIVATE_KEY': '', # Advanced settings 'PASSWORD_SCHEME': 'SHA512-CRYPT', # Host settings diff --git a/core/admin/mailu/ui/forms.py b/core/admin/mailu/ui/forms.py index 3c476c67..80d73fbe 100644 --- a/core/admin/mailu/ui/forms.py +++ b/core/admin/mailu/ui/forms.py @@ -79,6 +79,7 @@ class UserSignupForm(flask_wtf.FlaskForm): localpart = fields.StringField(_('Email address'), [validators.DataRequired(), validators.Regexp("^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+$")]) pw = fields.PasswordField(_('Password'), [validators.DataRequired()]) pw2 = fields.PasswordField(_('Confirm password'), [validators.EqualTo('pw')]) + captcha = flask_wtf.RecaptchaField() submit = fields.SubmitField(_('Sign up')) diff --git a/core/admin/mailu/ui/templates/user/signup.html b/core/admin/mailu/ui/templates/user/signup.html index eccd9f67..59c1a988 100644 --- a/core/admin/mailu/ui/templates/user/signup.html +++ b/core/admin/mailu/ui/templates/user/signup.html @@ -14,6 +14,7 @@ {% call macros.box() %} {{ macros.form_field(form.localpart, append='@'+domain.name+'') }} {{ macros.form_fields((form.pw, form.pw2)) }} + {{ macros.form_field(form.captcha) }} {{ macros.form_field(form.submit) }} {% endcall %} diff --git a/docs/compose/.env b/docs/compose/.env index 6f330b64..e5c67129 100644 --- a/docs/compose/.env +++ b/docs/compose/.env @@ -103,6 +103,10 @@ SITENAME=Mailu # Linked Website URL WEBSITE=https://mailu.io +# Registration reCaptcha settings (warning, this has some privacy impact) +# RECAPTCHA_PUBLIC_KEY= +# RECAPTCHA_PRIVATE_KEY= + ################################### # Advanced settings ###################################