From 1bbf3f235d41208b75939c486745226f47d9e508 Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Wed, 7 Nov 2018 09:58:49 +0200 Subject: [PATCH 1/2] Using a new class when captcha is enabled --- core/admin/mailu/ui/forms.py | 3 ++- core/admin/mailu/ui/views/users.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/admin/mailu/ui/forms.py b/core/admin/mailu/ui/forms.py index 4f7a30ae..57c106c3 100644 --- a/core/admin/mailu/ui/forms.py +++ b/core/admin/mailu/ui/forms.py @@ -90,9 +90,10 @@ class UserSignupForm(flask_wtf.FlaskForm): localpart = fields.StringField(_('Email address'), [validators.DataRequired(), validators.Regexp(LOCALPART_REGEX)]) pw = fields.PasswordField(_('Password'), [validators.DataRequired()]) pw2 = fields.PasswordField(_('Confirm password'), [validators.EqualTo('pw')]) - captcha = flask_wtf.RecaptchaField() submit = fields.SubmitField(_('Sign up')) +class UserSignupFormCaptcha(UserSignupForm): + captcha = flask_wtf.RecaptchaField() class UserSettingsForm(flask_wtf.FlaskForm): displayed_name = fields.StringField(_('Displayed name')) diff --git a/core/admin/mailu/ui/views/users.py b/core/admin/mailu/ui/views/users.py index c54d22ec..f7f75c32 100644 --- a/core/admin/mailu/ui/views/users.py +++ b/core/admin/mailu/ui/views/users.py @@ -170,7 +170,11 @@ def user_signup(domain_name=None): available_domains=available_domains) domain = available_domains.get(domain_name) or flask.abort(404) quota_bytes = domain.max_quota_bytes or app.config['DEFAULT_QUOTA'] - form = forms.UserSignupForm() + if app.config['RECAPTCHA_PUBLIC_KEY'] == "" or app.config['RECAPTCHA_PRIVATE_KEY'] == "": + form = forms.UserSignupForm() + else: + form = forms.UserSignupFormCaptcha() + if form.validate_on_submit(): if domain.has_email(form.localpart.data): flask.flash('Email is already used', 'error') From fed7146873c5de0f3fab288451242850c7c9c67d Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Fri, 9 Nov 2018 12:30:49 +0200 Subject: [PATCH 2/2] Captcha check on signup form --- core/admin/mailu/ui/templates/user/signup.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/admin/mailu/ui/templates/user/signup.html b/core/admin/mailu/ui/templates/user/signup.html index 59c1a988..f540d660 100644 --- a/core/admin/mailu/ui/templates/user/signup.html +++ b/core/admin/mailu/ui/templates/user/signup.html @@ -14,7 +14,9 @@ {% call macros.box() %} {{ macros.form_field(form.localpart, append='@'+domain.name+'') }} {{ macros.form_fields((form.pw, form.pw2)) }} - {{ macros.form_field(form.captcha) }} + {% if form.captcha %} + {{ macros.form_field(form.captcha) }} + {% endif %} {{ macros.form_field(form.submit) }} {% endcall %}