Skip to content

Commit

Permalink
Upgrade reCAPTCHA to v2. (see #688)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnga committed May 8, 2018
1 parent ff23aa9 commit e35f8c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions gobotany/plantshare/backends/default/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from captcha.fields import ReCaptchaField
from registration.forms import RegistrationForm

from snowpenguin.django.recaptcha2.fields import ReCaptchaField
from snowpenguin.django.recaptcha2.widgets import ReCaptchaWidget

class RegistrationFormWithCaptcha(RegistrationForm):
captcha = ReCaptchaField(attrs={'theme': 'clean'})
captcha = ReCaptchaField(widget=ReCaptchaWidget())
11 changes: 7 additions & 4 deletions gobotany/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
'haystack',
'haystack_panel',
'imagekit',
'snowpenguin.django.recaptcha2',
'tinymce',
'registration',
#'emailconfirmation', # Temporarily uncomment to create this app's
Expand Down Expand Up @@ -263,12 +264,14 @@
EMAIL_CONFIRMATION_DAYS = 3

# For django-recaptcha
if DEV_FEATURES:
RECAPTCHA_PUBLIC_KEY = os.environ.get('RECAPTCHA_PUBLIC_KEY_DEV', '')
RECAPTCHA_PRIVATE_KEY = os.environ.get('RECAPTCHA_PRIVATE_KEY_DEV', '')
else:
if IN_PRODUCTION: # Dev, Prod instances on Heroku
# Note: _DEV keys were generated to include Heroku Dev, so Dev may fail.
# TODO: may need to re-generate again: 1. Heroku (Prod, Dev), 2. Local
RECAPTCHA_PUBLIC_KEY = os.environ.get('RECAPTCHA_PUBLIC_KEY', '')
RECAPTCHA_PRIVATE_KEY = os.environ.get('RECAPTCHA_PRIVATE_KEY', '')
else: # local development
RECAPTCHA_PUBLIC_KEY = os.environ.get('RECAPTCHA_PUBLIC_KEY_DEV', '')
RECAPTCHA_PRIVATE_KEY = os.environ.get('RECAPTCHA_PRIVATE_KEY_DEV', '')
RECAPTCHA_USE_SSL = True

# For static Google Maps (dynamic ones use a different key, in google_maps.js)
Expand Down
3 changes: 3 additions & 0 deletions gobotany/site/templates/gobotany/_base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load gobotany_tags %}
{% load recaptcha2 %}
<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -50,6 +51,8 @@
{% include "gobotany/_google_analytics.html" %}
{% endif %}

{% recaptcha_init %}

{% block ember_templates %}{% endblock %}
</head>

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# Login and registration

'django-email-confirmation==0.2',
'django-recaptcha==1.0.5',
'django-recaptcha2==1.0.3',
'django-registration==2.1.1',

# For storing images on S3.
Expand Down

0 comments on commit e35f8c9

Please sign in to comment.