Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding RECAPTCHA_DISABLE to disable recaptcha #509

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Recaptcha
``RECAPTCHA_PUBLIC_KEY`` **required** A public key.
``RECAPTCHA_PRIVATE_KEY`` **required** A private key.
https://www.google.com/recaptcha/admin
``RECAPTCHA_DISABLE`` Disable recaptcha widgets.
Default is ``False``
``RECAPTCHA_PARAMETERS`` **optional** A dict of configuration options.
``RECAPTCHA_HTML`` **optional** Override default HTML template
for Recaptcha.
Expand Down
5 changes: 5 additions & 0 deletions docs/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ Example of RECAPTCHA_PARAMETERS, and RECAPTCHA_DATA_ATTRS::
For your convenience, when testing your application, if ``app.testing`` is ``True``, the recaptcha
field will always be valid.

In development environment or when you are offline you can disable all
recaptcha fields::

RECAPTCHA_DISABLE = True

And it can be easily setup in the templates:

.. sourcecode:: html+jinja
Expand Down
2 changes: 1 addition & 1 deletion src/flask_wtf/recaptcha/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, message=None):
self.message = message

def __call__(self, form, field):
if current_app.testing:
if current_app.testing or current_app.config.get("RECAPTCHA_DISABLE", False):
return True

if request.json:
Expand Down
3 changes: 3 additions & 0 deletions src/flask_wtf/recaptcha/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def recaptcha_html(self, public_key):
def __call__(self, field, error=None, **kwargs):
"""Returns the recaptcha input HTML."""

if current_app.config.get("RECAPTCHA_DISABLE", False):
return Markup("<!-- recaptcha disabled -->")

try:
public_key = current_app.config["RECAPTCHA_PUBLIC_KEY"]
except KeyError:
Expand Down