Skip to content

Saleor Core: the high performance, composable, headless commerce API.

As requested: enable recaptcha implicitly by settings both keys

NyanKiyoshi0ad81281ff04
diff --git a/docs/guides/recaptcha.rst b/docs/guides/recaptcha.rst
index f23f395fe7..4e286b58f0 100644
--- a/docs/guides/recaptcha.rst
+++ b/docs/guides/recaptcha.rst
@@ -14,11 +14,20 @@ Enable and Set-up
To enable ReCaptcha, you need to set those keys in your environment:
-1. ``ENABLE_RECAPTCHA`` to ``True``;
-2. ``RECAPTCHA_PUBLIC_KEY`` to your public/ site API key;
-3. ``RECAPTCHA_PRIVATE_KEY`` to your secret/ private API key.
+1. ``RECAPTCHA_PUBLIC_KEY`` to your public/ site API key;
+2. ``RECAPTCHA_PRIVATE_KEY`` to your secret/ private API key.
.. note::
- You are not required to set your public and private keys for development use.
- You only have to set them up if you are using Saleor for production (Google will remind you if you do not).
+ You are not required to set your public and private keys for development use. You can use the following development keys:
+
+ .. table::
+
+ ===================== ========================================
+ Key Value
+ ===================== ========================================
+ RECAPTCHA_PUBLIC_KEY 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
+ RECAPTCHA_PRIVATE_KEY 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
+ ===================== ========================================
+
+ You only have to set them up if you are using Saleor for production (Google will remind you if you do not).
diff --git a/saleor/account/forms.py b/saleor/account/forms.py
index 7428ca893f..a940c2eb91 100644
--- a/saleor/account/forms.py
+++ b/saleor/account/forms.py
@@ -12,7 +12,7 @@ from .i18n import AddressMetaForm, get_address_form_class
class FormWithReCaptcha(forms.BaseForm):
def __new__(cls, *args, **kwargs):
- if settings.ENABLE_RECAPTCHA:
+ if settings.RECAPTCHA_PUBLIC_KEY and settings.RECAPTCHA_PRIVATE_KEY:
# insert a Google reCaptcha field inside the form
# note: label is empty, the reCaptcha is self-explanatory making
# the form simpler for the user.
diff --git a/saleor/settings.py b/saleor/settings.py
index 769a00c49d..83eda0f192 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -4,7 +4,6 @@ import os.path
import dj_database_url
import dj_email_url
import django_cache_url
-from captcha import constants as recaptcha_constants
from django.contrib.messages import constants as messages
from django.utils.translation import gettext_lazy as _
from django_prices.templatetags.prices_i18n import get_currency_fraction
@@ -485,16 +484,11 @@ DEFAULT_MENUS = {
'top_menu_name': 'navbar',
'bottom_menu_name': 'footer'}
-# Enable or not Google's reCaptcha on account forms
-ENABLE_RECAPTCHA = get_bool_from_env('ENABLE_RECAPTCHA', False)
-
-# Set Google's reCaptcha keys
-RECAPTCHA_PUBLIC_KEY = os.environ.get(
- 'RECAPTCHA_PUBLIC_KEY', recaptcha_constants.TEST_PUBLIC_KEY)
-RECAPTCHA_PRIVATE_KEY = os.environ.get(
- 'RECAPTCHA_PRIVATE_KEY', recaptcha_constants.TEST_PUBLIC_KEY)
-
# This enable the new 'No Captcha reCaptcha' version (the simple checkbox)
# instead of the old (deprecated) one. For more information see:
# https://github.com/praekelt/django-recaptcha/blob/34af16ba1e/README.rst
NOCAPTCHA = True
+
+# Set Google's reCaptcha keys
+RECAPTCHA_PUBLIC_KEY = os.environ.get('RECAPTCHA_PUBLIC_KEY')
+RECAPTCHA_PRIVATE_KEY = os.environ.get('RECAPTCHA_PRIVATE_KEY')
diff --git a/tests/settings.py b/tests/settings.py
index 888e593adc..a7ca66209c 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -6,7 +6,9 @@ SECRET_KEY = 'NOTREALLY'
DEFAULT_CURRENCY = 'USD'
LANGUAGE_CODE = 'en'
-ENABLE_RECAPTCHA = False
+
+RECAPTCHA_PUBLIC_KEY = None
+RECAPTCHA_PRIVATE_KEY = None
VATLAYER_ACCESS_KEY = ''
diff --git a/tests/test_account.py b/tests/test_account.py
index 907b4d2622..c5e7fe064a 100644
--- a/tests/test_account.py
+++ b/tests/test_account.py
@@ -5,6 +5,7 @@ from urllib.parse import urlencode
import i18naddress
import pytest
+from captcha import constants as recaptcha_constants
from django.conf import settings
from django.core.exceptions import ValidationError
from django.forms import Form
@@ -238,7 +239,10 @@ def test_disabled_recaptcha():
@patch.dict(os.environ, {'RECAPTCHA_TESTING': 'True'})
[email protected](settings, 'ENABLE_RECAPTCHA', True)
+ settings, 'RECAPTCHA_PUBLIC_KEY', recaptcha_constants.TEST_PUBLIC_KEY)
+ settings, 'RECAPTCHA_PRIVATE_KEY', recaptcha_constants.TEST_PRIVATE_KEY)
def test_requires_recaptcha():
"""
This test creates a new form