From 334df6e43611b9ccb3dc6d4d2a5b7599b7b0ab37 Mon Sep 17 00:00:00 2001 From: ryosuketc Date: Wed, 15 Sep 2021 06:13:00 +0000 Subject: [PATCH] Require reCAPTCHA to create person records. #779 --- app/create.py | 15 +++++++++++++++ app/resources/add_note_base.html.template | 6 ++++++ app/resources/create.html.template | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/create.py b/app/create.py index 569b64c95f..cdcbd20eb1 100644 --- a/app/create.py +++ b/app/create.py @@ -16,6 +16,7 @@ import photo from utils import * from detect_spam import SpamDetector +from recaptcha.client import captcha import subscribe import simplejson @@ -385,11 +386,25 @@ def get(self): add_profile_icon_url(website, self.transitionary_get_url) for website in self.config.profile_websites or []] self.render('create.html', + captcha_html=self.get_captcha_html(), profile_websites=profile_websites, profile_websites_json=simplejson.dumps(profile_websites), onload_function='view_page_loaded') def post(self): + captcha_response = self.get_captcha_response() + if not captcha_response.is_valid: + self.params.create_mode = True + profile_websites = [ + add_profile_icon_url(website, self.transitionary_get_url) + for website in self.config.profile_websites or []] + self.render('create.html', + captcha_html=self.get_captcha_html(), + profile_websites=profile_websites, + profile_websites_json=simplejson.dumps(profile_websites), + onload_function='view_page_loaded') + return + profile_urls = [self.params.profile_url1, self.params.profile_url2, self.params.profile_url3] diff --git a/app/resources/add_note_base.html.template b/app/resources/add_note_base.html.template index 2407417f72..a58769d001 100644 --- a/app/resources/add_note_base.html.template +++ b/app/resources/add_note_base.html.template @@ -299,6 +299,12 @@ {% endif %} +{% if enable_recaptcha %} +
+ {{captcha_html|safe}} +
+{% endif %} +
{% ifequal params.role "provide" %} - {% include "add_note_base.html.template" %} + {% include "add_note_base.html.template" with enable_recaptcha=True %} {% endifequal %} {% ifnotequal params.role "provide" %}