Skip to content

Commit

Permalink
Require reCAPTCHA to create person records. #779 (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryosuketc authored Sep 16, 2021
1 parent 1f52fdd commit 80dff4b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
12 changes: 11 additions & 1 deletion app/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import photo
from utils import *
from detect_spam import SpamDetector
from recaptcha.client import captcha
import subscribe
import simplejson

Expand Down Expand Up @@ -379,17 +380,26 @@ def create_note(


class Handler(BaseHandler):
def get(self):
def _render_create_html(self):
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')

def get(self):
self._render_create_html()

def post(self):
captcha_response = self.get_captcha_response()
if not captcha_response.is_valid:
self._render_create_html()
return

profile_urls = [self.params.profile_url1,
self.params.profile_url2,
self.params.profile_url3]
Expand Down
5 changes: 3 additions & 2 deletions app/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ indexes:
# index.yaml file manually, remove the above marker line (the line
# saying "# AUTOGENERATED"). If you want to manage some indexes
# manually, move them above the marker line. The index.yaml file is
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
# automatically uploaded to Cloud Datastore when you next deploy
# your application using 'gcloud app deploy' or create the indexes
# using 'gcloud datastore indexes create'.

- kind: ApiActionLog
properties:
Expand Down
6 changes: 6 additions & 0 deletions app/resources/add_note_base.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@
</div>
{% endif %}

{% if enable_recaptcha %}
<div class="recaptcha">
{{captcha_html|safe}}
</div>
{% endif %}

<div class="submit button button-blue">
<input type="submit"
{% if person.notes_disabled %}
Expand Down
5 changes: 4 additions & 1 deletion app/resources/create.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,13 @@
</div>

{% 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" %}
<div class="recaptcha">
{{captcha_html|safe}}
</div>
<div class="submit button button-blue">
<input type="submit"
value="{% trans "Save this record" %}"
Expand Down
6 changes: 6 additions & 0 deletions app/resources/css-default.template
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,12 @@ label.option {
min-width: 50%;
}

/* reCAPTCHA */
.create .recaptcha {
margin: 0 auto;
width: 302px; /* Defined in captcha.get_display_html */
}

.source .instructions {
padding-top: 1em;
padding-bottom: 1em;
Expand Down
6 changes: 6 additions & 0 deletions app/resources/css-light.template
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ label.option {
min-width: 50%;
}

/* reCAPTCHA */
.create .recaptcha {
margin: 0 auto;
width: 302px; /* Defined in captcha.get_display_html. */
}

.source .instructions {
padding-top: 1em;
padding-bottom: 1em;
Expand Down

0 comments on commit 80dff4b

Please sign in to comment.