From 9708b809d41feaf04f4a479df3ee84892e8a5de6 Mon Sep 17 00:00:00 2001 From: Renato Covarrubias Date: Fri, 11 Dec 2015 23:44:09 -0300 Subject: [PATCH 1/5] Adding RECAPTCHA_DISABLE to disable recaptcha. Useful when you are offline. --- docs/config.rst | 2 ++ docs/form.rst | 5 +++++ flask_wtf/recaptcha/validators.py | 2 +- flask_wtf/recaptcha/widgets.py | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/config.rst b/docs/config.rst index f4bbc01e..4f2d9d45 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -41,6 +41,8 @@ You have already learned these configuration at :ref:`recaptcha`. This table is only designed for a convience. ======================= ============================================== +RECAPTCHA_DISABLE Disable recaptcha widgets. + Default is False RECAPTCHA_USE_SSL Enable/disable recaptcha through ssl. Default is False. RECAPTCHA_PUBLIC_KEY **required** A public key. diff --git a/docs/form.rst b/docs/form.rst index 8888a367..114bc16c 100644 --- a/docs/form.rst +++ b/docs/form.rst @@ -147,6 +147,11 @@ Example of RECAPTCHA_PARAMETERS, and RECAPTCHA_DATA_ATTRS:: For testing your application, if ``app.testing`` is ``True``, recaptcha field will always be valid for you convenience. +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 diff --git a/flask_wtf/recaptcha/validators.py b/flask_wtf/recaptcha/validators.py index bcff23d3..ed1b8ac3 100644 --- a/flask_wtf/recaptcha/validators.py +++ b/flask_wtf/recaptcha/validators.py @@ -31,7 +31,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: diff --git a/flask_wtf/recaptcha/widgets.py b/flask_wtf/recaptcha/widgets.py index 71a10065..17401027 100644 --- a/flask_wtf/recaptcha/widgets.py +++ b/flask_wtf/recaptcha/widgets.py @@ -34,6 +34,8 @@ 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 '' try: public_key = current_app.config['RECAPTCHA_PUBLIC_KEY'] except KeyError: From f0f30238339f5400cd0e4e2ba3914492ef00f90a Mon Sep 17 00:00:00 2001 From: Renato Covarrubias Date: Sat, 12 Dec 2015 00:06:47 -0300 Subject: [PATCH 2/5] Tab -> 8 spaces. Sorry --- flask_wtf/recaptcha/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_wtf/recaptcha/widgets.py b/flask_wtf/recaptcha/widgets.py index 17401027..b4872fa2 100644 --- a/flask_wtf/recaptcha/widgets.py +++ b/flask_wtf/recaptcha/widgets.py @@ -35,7 +35,7 @@ def __call__(self, field, error=None, **kwargs): """Returns the recaptcha input HTML.""" if current_app.config.get('RECAPTCHA_DISABLE', False): - return '' + return '' try: public_key = current_app.config['RECAPTCHA_PUBLIC_KEY'] except KeyError: From 9bb590f8a91c435911f516cb2bd08783e7712760 Mon Sep 17 00:00:00 2001 From: Renato Covarrubias Date: Sat, 12 Dec 2015 00:15:52 -0300 Subject: [PATCH 3/5] Fix message in html comment when recaptcha is disabled --- flask_wtf/recaptcha/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_wtf/recaptcha/widgets.py b/flask_wtf/recaptcha/widgets.py index b4872fa2..74bbaa03 100644 --- a/flask_wtf/recaptcha/widgets.py +++ b/flask_wtf/recaptcha/widgets.py @@ -35,7 +35,7 @@ def __call__(self, field, error=None, **kwargs): """Returns the recaptcha input HTML.""" if current_app.config.get('RECAPTCHA_DISABLE', False): - return '' + return Markup(u'') try: public_key = current_app.config['RECAPTCHA_PUBLIC_KEY'] except KeyError: From bf91148bb06c2fde5330a869072f048da68256a0 Mon Sep 17 00:00:00 2001 From: Renato Covarrubias Date: Wed, 9 Mar 2022 22:54:22 -0300 Subject: [PATCH 4/5] Delete extra : --- src/flask_wtf/recaptcha/validators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flask_wtf/recaptcha/validators.py b/src/flask_wtf/recaptcha/validators.py index d923f97e..f01a09fa 100644 --- a/src/flask_wtf/recaptcha/validators.py +++ b/src/flask_wtf/recaptcha/validators.py @@ -27,7 +27,7 @@ def __init__(self, message=None): self.message = message def __call__(self, form, field): - if current_app.testing or current_app.config.get('RECAPTCHA_DISABLE', False):: + if current_app.testing or current_app.config.get('RECAPTCHA_DISABLE', False): return True if request.json: From 0fd19e5da74b9724451e842fc8502692cc9f97b1 Mon Sep 17 00:00:00 2001 From: Renato Covarrubias Date: Wed, 9 Mar 2022 22:56:16 -0300 Subject: [PATCH 5/5] Apply black --- src/flask_wtf/recaptcha/validators.py | 2 +- src/flask_wtf/recaptcha/widgets.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flask_wtf/recaptcha/validators.py b/src/flask_wtf/recaptcha/validators.py index f01a09fa..ed248157 100644 --- a/src/flask_wtf/recaptcha/validators.py +++ b/src/flask_wtf/recaptcha/validators.py @@ -27,7 +27,7 @@ def __init__(self, message=None): self.message = message def __call__(self, form, field): - if current_app.testing or current_app.config.get('RECAPTCHA_DISABLE', False): + if current_app.testing or current_app.config.get("RECAPTCHA_DISABLE", False): return True if request.json: diff --git a/src/flask_wtf/recaptcha/widgets.py b/src/flask_wtf/recaptcha/widgets.py index 603cb464..be2530be 100644 --- a/src/flask_wtf/recaptcha/widgets.py +++ b/src/flask_wtf/recaptcha/widgets.py @@ -37,8 +37,8 @@ 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(u'') + if current_app.config.get("RECAPTCHA_DISABLE", False): + return Markup("") try: public_key = current_app.config["RECAPTCHA_PUBLIC_KEY"]