Add simple captcha

This commit is contained in:
rubenwardy 2021-04-17 02:08:54 +01:00
parent 3612c1747e
commit c0719fdeaa
3 changed files with 16 additions and 5 deletions

@ -105,11 +105,16 @@ class RegisterForm(FlaskForm):
Regexp("^[a-zA-Z0-9._-]+$", message="Only a-zA-Z0-9._ allowed")])
email = StringField("Email", [InputRequired(), Email()])
password = PasswordField("Password", [InputRequired(), Length(6, 100)])
agree = BooleanField("I agree", [Required()])
question = StringField("What is the result of the above calculation?", [InputRequired()])
agree = BooleanField("I agree", [DataRequired()])
submit = SubmitField("Register")
def handle_register(form):
if form.question.data.strip().lower() != "19":
flash("Incorrect captcha answer", "danger")
return
user_by_name = User.query.filter(or_(
User.username == form.username.data,
User.username == form.display_name.data,
@ -168,7 +173,8 @@ def register():
if ret:
return ret
return render_template("users/register.html", form=form, suggested_password=genphrase(entropy=52, wordset="bip39"))
return render_template("users/register.html", form=form,
suggested_password=genphrase(entropy=52, wordset="bip39"))
class ForgotPasswordForm(FlaskForm):

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

@ -32,6 +32,11 @@ Register
<code>{{ suggested_password }}</code>
</p>
<p>
<img src="/static/puzzle.png" />
</p>
{{ render_field(form.question, hint=_("Please prove that you are human")) }}
{% set label %}
{{ _("I agree to the ") }}
<a href="{{ url_for('flatpage', path='privacy_policy') }} ">