diff --git a/setup/website_recaptcha_v2/odoo/addons/website_recaptcha_v2 b/setup/website_recaptcha_v2/odoo/addons/website_recaptcha_v2 new file mode 120000 index 0000000000..8ea48c47d8 --- /dev/null +++ b/setup/website_recaptcha_v2/odoo/addons/website_recaptcha_v2 @@ -0,0 +1 @@ +../../../../website_recaptcha_v2 \ No newline at end of file diff --git a/setup/website_recaptcha_v2/setup.py b/setup/website_recaptcha_v2/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_recaptcha_v2/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_recaptcha_v2/README.rst b/website_recaptcha_v2/README.rst new file mode 100644 index 0000000000..bb3b7e2f3b --- /dev/null +++ b/website_recaptcha_v2/README.rst @@ -0,0 +1,106 @@ +==================== +Website reCAPTCHA v2 +==================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:55856dbbdf9c9efc1b9b1ebbb33638a0018eda0d91bd6c8c9e30805aa8f2e5b0 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github + :target: https://github.com/OCA/website/tree/16.0/website_recaptcha_v2 + :alt: OCA/website +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/website-16-0/website-16-0-website_recaptcha_v2 + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to use reCAPTCHA v2 on website forms. + +It is a helper module that only provides the widget and the validation logic +which can be used by other modules to actually display it on website forms and +check whether the user entry is valid. + +This module originally comes from ``website_recaptcha_reloaded`` from Tech +Receptives, which itself comes from ``website_recaptcha`` from Elico Corp. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +reCAPTCHA is configured in Settings > Website. It can be enabled or disabled +using the checkbox, and the site and secret keys can be defined there when it +is enabled. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Elico Corp +* Tech Receptives +* Coop IT Easy SC + +Contributors +~~~~~~~~~~~~ + +* `Elico Corp `_: + + * Augustin Cisterne-Kaas +* `Tech Receptives `_: + + * Parthiv Patel + * Hardik Kalariya + +* `Coop IT Easy SC `_: + + * Houssine Bakkali + * Robin Keunen + * Carmen Bianca Bakker + * Victor Champonnois + * hugues de keyzer + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/website `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_recaptcha_v2/__init__.py b/website_recaptcha_v2/__init__.py new file mode 100644 index 0000000000..d4f336984c --- /dev/null +++ b/website_recaptcha_v2/__init__.py @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: 2010-2014 Elico Corp +# SPDX-FileContributor: Augustin Cisterne-Kaas +# SPDX-FileCopyrightText: 2015 Tech-Receptives Solutions Pvt. Ltd. +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import models diff --git a/website_recaptcha_v2/__manifest__.py b/website_recaptcha_v2/__manifest__.py new file mode 100644 index 0000000000..f8486bfc22 --- /dev/null +++ b/website_recaptcha_v2/__manifest__.py @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: 2010-2014 Elico Corp +# SPDX-FileContributor: Augustin Cisterne-Kaas +# SPDX-FileCopyrightText: 2015 Tech-Receptives Solutions Pvt. Ltd. +# SPDX-FileCopyrightText: 2019 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +{ + "name": "Website reCAPTCHA v2", + "version": "16.0.1.0.0", + "category": "Website", + "depends": ["website"], + "author": ( + "Elico Corp, Tech Receptives, Coop IT Easy SC, " + "Odoo Community Association (OCA)" + ), + "license": "AGPL-3", + "website": "https://github.com/OCA/website", + "summary": "Helper module to add reCAPTCHA v2 to website forms", + "data": [ + "views/res_config_settings_view.xml", + "views/website_templates.xml", + ], + "demo": [ + "demo/demo.xml", + ], +} diff --git a/website_recaptcha_v2/demo/demo.xml b/website_recaptcha_v2/demo/demo.xml new file mode 100644 index 0000000000..8630a6f52e --- /dev/null +++ b/website_recaptcha_v2/demo/demo.xml @@ -0,0 +1,22 @@ + + + + + + True + + 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI + 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe + + + diff --git a/website_recaptcha_v2/i18n/website_recaptcha_v2.pot b/website_recaptcha_v2/i18n/website_recaptcha_v2.pot new file mode 100644 index 0000000000..f5ecd949d3 --- /dev/null +++ b/website_recaptcha_v2/i18n/website_recaptcha_v2.pot @@ -0,0 +1,103 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_recaptcha_reloaded +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_recaptcha_reloaded +#: model_terms:ir.ui.view,arch_db:website_recaptcha_reloaded.view_website_config_settings +msgid "\n" +" How to get my reCaptcha Key" +msgstr "" + +#. module: website_recaptcha_reloaded +#: model_terms:ir.ui.view,arch_db:website_recaptcha_reloaded.view_website_config_settings +msgid "" +msgstr "" + +#. module: website_recaptcha_reloaded +#: model:ir.model,name:website_recaptcha_reloaded.model_res_config_settings +msgid "Config Settings" +msgstr "" + +#. module: website_recaptcha_reloaded +#: model:ir.model.fields,field_description:website_recaptcha_reloaded.field_res_config_settings__has_google_recaptcha +msgid "Google reCaptcha" +msgstr "" + +#. module: website_recaptcha_reloaded +#: model_terms:ir.ui.view,arch_db:website_recaptcha_reloaded.view_website_config_settings +msgid "Protect your forms using reCaptcha control." +msgstr "" + +#. module: website_recaptcha_reloaded +#: model:ir.model.fields,field_description:website_recaptcha_reloaded.field_res_config_settings__recaptcha_key_secret +#: model:ir.model.fields,field_description:website_recaptcha_reloaded.field_website__recaptcha_key_secret +msgid "Recaptcha Key Secret" +msgstr "" + +#. module: website_recaptcha_reloaded +#: model:ir.model.fields,field_description:website_recaptcha_reloaded.field_res_config_settings__recaptcha_key_site +#: model:ir.model.fields,field_description:website_recaptcha_reloaded.field_website__recaptcha_key_site +msgid "Recaptcha Key Site" +msgstr "" + +#. module: website_recaptcha_reloaded +#: code:addons/website_recaptcha_reloaded/website.py:24 +#, python-format +msgid "The response parameter is invalid or malformed." +msgstr "" + +#. module: website_recaptcha_reloaded +#: code:addons/website_recaptcha_reloaded/website.py:23 +#, python-format +msgid "The response parameter is missing." +msgstr "" + +#. module: website_recaptcha_reloaded +#: code:addons/website_recaptcha_reloaded/website.py:22 +#, python-format +msgid "The secret parameter is invalid or malformed." +msgstr "" + +#. module: website_recaptcha_reloaded +#: code:addons/website_recaptcha_reloaded/website.py:21 +#, python-format +msgid "The secret parameter is missing." +msgstr "" + +#. module: website_recaptcha_reloaded +#: code:addons/website_recaptcha_reloaded/website.py:29 +#, python-format +msgid "There was a problem with the captcha entry." +msgstr "" + +#. module: website_recaptcha_reloaded +#: model:ir.model,name:website_recaptcha_reloaded.model_website +msgid "Website" +msgstr "" + +#. module: website_recaptcha_reloaded +#: model_terms:ir.ui.view,arch_db:website_recaptcha_reloaded.view_website_config_settings +msgid "XXXXX" +msgstr "" + +#. module: website_recaptcha_reloaded +#: model_terms:ir.ui.view,arch_db:website_recaptcha_reloaded.view_website_config_settings +msgid "captcha" +msgstr "" + +#. module: website_recaptcha_reloaded +#: model_terms:ir.ui.view,arch_db:website_recaptcha_reloaded.view_website_config_settings +msgid "reCaptcha" +msgstr "" + diff --git a/website_recaptcha_v2/models/__init__.py b/website_recaptcha_v2/models/__init__.py new file mode 100644 index 0000000000..2224c4284e --- /dev/null +++ b/website_recaptcha_v2/models/__init__.py @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2010-2014 Elico Corp +# SPDX-FileContributor: Augustin Cisterne-Kaas +# SPDX-FileCopyrightText: 2015 Tech-Receptives Solutions Pvt. Ltd. +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import res_config_settings +from . import website diff --git a/website_recaptcha_v2/models/res_config_settings.py b/website_recaptcha_v2/models/res_config_settings.py new file mode 100644 index 0000000000..fa2e0cf47f --- /dev/null +++ b/website_recaptcha_v2/models/res_config_settings.py @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2010-2014 Elico Corp +# SPDX-FileContributor: Augustin Cisterne-Kaas +# SPDX-FileCopyrightText: 2015 Tech-Receptives Solutions Pvt. Ltd. +# SPDX-FileCopyrightText: 2019 Simone Orsi - Camptocamp SA +# SPDX-FileCopyrightText: 2019 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + recaptcha_v2_enabled = fields.Boolean( + related="website_id.recaptcha_v2_enabled", readonly=False + ) + recaptcha_v2_site_key = fields.Char( + related="website_id.recaptcha_v2_site_key", readonly=False + ) + recaptcha_v2_secret_key = fields.Char( + related="website_id.recaptcha_v2_secret_key", readonly=False + ) diff --git a/website_recaptcha_v2/models/website.py b/website_recaptcha_v2/models/website.py new file mode 100644 index 0000000000..f0b43094a7 --- /dev/null +++ b/website_recaptcha_v2/models/website.py @@ -0,0 +1,77 @@ +# SPDX-FileCopyrightText: 2010-2014 Elico Corp +# SPDX-FileContributor: Augustin Cisterne-Kaas +# SPDX-FileCopyrightText: 2015 Tech-Receptives Solutions Pvt. Ltd. +# SPDX-FileCopyrightText: 2019 Simone Orsi - Camptocamp SA +# SPDX-FileCopyrightText: 2019 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +import requests + +from odoo import _, api, fields, models + +RECAPTCHA_API_URL = "https://www.recaptcha.net/recaptcha/api/siteverify" +RECAPTCHA_API_TIMEOUT = 30 + + +class Website(models.Model): + _inherit = "website" + + recaptcha_v2_enabled = fields.Boolean("Enable reCAPTCHA v2") + recaptcha_v2_site_key = fields.Char("Site Key (v2)") + recaptcha_v2_secret_key = fields.Char("Secret Key (v2)") + + @api.model + def _get_error_message(self, errorcode=None): + mapping = { + "missing-input-secret": _("The secret parameter is missing."), + "invalid-input-secret": _("The secret parameter is invalid or malformed."), + "missing-input-response": _("The response parameter is missing."), + "invalid-input-response": _( + "The response parameter is invalid or malformed." + ), + "bad-request": _("The request is invalid or malformed."), + "timeout-or-duplicate": _( + "The response is no longer valid: either is too old or has " + "been used previously." + ), + } + return mapping.get( + errorcode, + _( + "Unknown reCAPTCHA error (error code: {errorcode}).".format( + errorcode=errorcode + ) + ), + ) + + def is_recaptcha_v2_valid(self, form_values): + """ + Checks whether the reCAPTCHA v2 challenge has been correctly solved. + + form_values must be a dictionary containing the form values. + + Returns a (bool, str) tuple. The first element tells whether the + CAPTCHA is valid or not. The second is the error message when + applicable (or an empty string). + + If reCAPTCHA is disabled in the settings, this method behaves as if + the CAPTCHA was correctly solved, but without doing any check. + """ + if not self.recaptcha_v2_enabled: + return (True, "") + response = form_values.get("g-recaptcha-response") + if not response: + return (False, _("No response given.")) + get_res = {"secret": self.recaptcha_v2_secret_key, "response": response} + res = requests.post( + RECAPTCHA_API_URL, data=get_res, timeout=RECAPTCHA_API_TIMEOUT + ).json() + error_msg = "\n".join( + self._get_error_message(error) for error in res.get("error-codes", []) + ) + if error_msg: + return (False, error_msg) + if not res.get("success"): + return (False, _("The challenge was not successfully completed.")) + return (True, "") diff --git a/website_recaptcha_v2/readme/CONFIGURE.rst b/website_recaptcha_v2/readme/CONFIGURE.rst new file mode 100644 index 0000000000..14e14fe26e --- /dev/null +++ b/website_recaptcha_v2/readme/CONFIGURE.rst @@ -0,0 +1,3 @@ +reCAPTCHA is configured in Settings > Website. It can be enabled or disabled +using the checkbox, and the site and secret keys can be defined there when it +is enabled. diff --git a/website_recaptcha_v2/readme/CONTRIBUTORS.rst b/website_recaptcha_v2/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..caade69fea --- /dev/null +++ b/website_recaptcha_v2/readme/CONTRIBUTORS.rst @@ -0,0 +1,15 @@ +* `Elico Corp `_: + + * Augustin Cisterne-Kaas +* `Tech Receptives `_: + + * Parthiv Patel + * Hardik Kalariya + +* `Coop IT Easy SC `_: + + * Houssine Bakkali + * Robin Keunen + * Carmen Bianca Bakker + * Victor Champonnois + * hugues de keyzer diff --git a/website_recaptcha_v2/readme/DESCRIPTION.rst b/website_recaptcha_v2/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..3184f04b88 --- /dev/null +++ b/website_recaptcha_v2/readme/DESCRIPTION.rst @@ -0,0 +1,8 @@ +This module allows to use reCAPTCHA v2 on website forms. + +It is a helper module that only provides the widget and the validation logic +which can be used by other modules to actually display it on website forms and +check whether the user entry is valid. + +This module originally comes from ``website_recaptcha_reloaded`` from Tech +Receptives, which itself comes from ``website_recaptcha`` from Elico Corp. diff --git a/website_recaptcha_v2/static/description/index.html b/website_recaptcha_v2/static/description/index.html new file mode 100644 index 0000000000..7462acfab1 --- /dev/null +++ b/website_recaptcha_v2/static/description/index.html @@ -0,0 +1,451 @@ + + + + + + +Website reCAPTCHA v2 + + + +
+

Website reCAPTCHA v2

+ + +

Beta License: AGPL-3 OCA/website Translate me on Weblate Try me on Runboat

+

This module allows to use reCAPTCHA v2 on website forms.

+

It is a helper module that only provides the widget and the validation logic +which can be used by other modules to actually display it on website forms and +check whether the user entry is valid.

+

This module originally comes from website_recaptcha_reloaded from Tech +Receptives, which itself comes from website_recaptcha from Elico Corp.

+

Table of contents

+ +
+

Configuration

+

reCAPTCHA is configured in Settings > Website. It can be enabled or disabled +using the checkbox, and the site and secret keys can be defined there when it +is enabled.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Elico Corp
  • +
  • Tech Receptives
  • +
  • Coop IT Easy SC
  • +
+
+
+

Contributors

+
    +
  • Elico Corp:
      +
    • Augustin Cisterne-Kaas
    • +
    +
  • +
  • Tech Receptives:
      +
    • Parthiv Patel
    • +
    • Hardik Kalariya
    • +
    +
  • +
  • Coop IT Easy SC:
      +
    • Houssine Bakkali
    • +
    • Robin Keunen
    • +
    • Carmen Bianca Bakker
    • +
    • Victor Champonnois
    • +
    • hugues de keyzer
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/website project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/website_recaptcha_v2/static/description/recaptcha_ico.png b/website_recaptcha_v2/static/description/recaptcha_ico.png new file mode 100644 index 0000000000..65f4e0147f Binary files /dev/null and b/website_recaptcha_v2/static/description/recaptcha_ico.png differ diff --git a/website_recaptcha_v2/tests/__init__.py b/website_recaptcha_v2/tests/__init__.py new file mode 100644 index 0000000000..85b4755580 --- /dev/null +++ b/website_recaptcha_v2/tests/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import test_recaptcha diff --git a/website_recaptcha_v2/tests/test_recaptcha.py b/website_recaptcha_v2/tests/test_recaptcha.py new file mode 100644 index 0000000000..4af83acdc1 --- /dev/null +++ b/website_recaptcha_v2/tests/test_recaptcha.py @@ -0,0 +1,128 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from unittest import mock + +from odoo.tests.common import TransactionCase + +imp_requests = "odoo.addons.website_recaptcha_v2.models.website.requests" + + +class TestRecaptcha(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.website = cls.env.ref("website.default_website") + cls.website.write( + { + "recaptcha_v2_enabled": True, + "recaptcha_v2_site_key": "test-site", + "recaptcha_v2_secret_key": "test-secret", + } + ) + + @mock.patch(imp_requests) + def test_captcha_http_request(self, requests_mock): + self.website.is_recaptcha_v2_valid({"g-recaptcha-response": "dummy_response"}) + requests_mock.post.assert_called_once_with( + "https://www.recaptcha.net/recaptcha/api/siteverify", + data={ + "secret": "test-secret", + "response": "dummy_response", + }, + timeout=30, + ) + + @mock.patch(imp_requests) + def test_captcha_valid(self, requests_mock): + requests_mock.post().json.return_value = {"success": True} + result, error_msg = self.website.is_recaptcha_v2_valid( + {"g-recaptcha-response": "dummy_response"} + ) + self.assertTrue(result) + self.assertEqual(error_msg, "") + + @mock.patch(imp_requests) + def test_captcha_single_error(self, requests_mock): + requests_mock.post().json.return_value = { + "error-codes": ["missing-input-secret"] + } + result, error_msg = self.website.is_recaptcha_v2_valid( + {"g-recaptcha-response": "dummy_response"} + ) + self.assertFalse(result) + self.assertEqual(error_msg, "The secret parameter is missing.") + + @mock.patch(imp_requests) + def test_captcha_multiple_errors(self, requests_mock): + requests_mock.post().json.return_value = { + "error-codes": ["invalid-input-secret", "missing-input-response"] + } + result, error_msg = self.website.is_recaptcha_v2_valid( + {"g-recaptcha-response": "dummy_response"} + ) + self.assertFalse(result) + self.assertEqual( + error_msg, + "The secret parameter is invalid or malformed.\n" + "The response parameter is missing.", + ) + + @mock.patch(imp_requests) + def test_captcha_false_success(self, requests_mock): + requests_mock.post().json.return_value = {"success": False} + result, error_msg = self.website.is_recaptcha_v2_valid( + {"g-recaptcha-response": "dummy_response"} + ) + self.assertFalse(result) + self.assertEqual(error_msg, "The challenge was not successfully completed.") + + @mock.patch(imp_requests) + def test_captcha_empty_response(self, requests_mock): + requests_mock.post().json.return_value = {} + result, error_msg = self.website.is_recaptcha_v2_valid( + {"g-recaptcha-response": "dummy_response"} + ) + self.assertFalse(result) + self.assertEqual(error_msg, "The challenge was not successfully completed.") + + @mock.patch(imp_requests) + def test_captcha_unknown_error(self, requests_mock): + requests_mock.post().json.return_value = {"error-codes": ["unknown-error"]} + result, error_msg = self.website.is_recaptcha_v2_valid( + {"g-recaptcha-response": "dummy_response"} + ) + self.assertFalse(result) + self.assertEqual( + error_msg, "Unknown reCAPTCHA error (error code: unknown-error)." + ) + + @mock.patch(imp_requests) + def test_captcha_no_errors_and_success(self, requests_mock): + requests_mock.post().json.return_value = { + "error-codes": [], + "success": True, + } + result, error_msg = self.website.is_recaptcha_v2_valid( + {"g-recaptcha-response": "dummy_response"} + ) + self.assertTrue(result) + self.assertEqual(error_msg, "") + + def test_captcha_no_response(self): + result, error_msg = self.website.is_recaptcha_v2_valid({}) + self.assertFalse(result) + self.assertEqual(error_msg, "No response given.") + + @mock.patch(imp_requests) + def test_captcha_disabled(self, requests_mock): + self.env["ir.config_parameter"].sudo().set_param( + "portal_recaptcha.recaptcha_v2_enabled", False + ) + result, error_msg = self.website.is_recaptcha_v2_valid( + {"g-recaptcha-response": "dummy_response"} + ) + self.assertTrue(result) + self.assertEqual(error_msg, "") + requests_mock.assert_not_called() diff --git a/website_recaptcha_v2/views/res_config_settings_view.xml b/website_recaptcha_v2/views/res_config_settings_view.xml new file mode 100644 index 0000000000..cdfa5397b5 --- /dev/null +++ b/website_recaptcha_v2/views/res_config_settings_view.xml @@ -0,0 +1,81 @@ + + + + + + Website settings + res.config.settings + + + +

reCAPTCHA v2

+
+
+
+ +
+
+ reCAPTCHA icon +
+
+
+
+
+
+ +
diff --git a/website_recaptcha_v2/views/website_templates.xml b/website_recaptcha_v2/views/website_templates.xml new file mode 100644 index 0000000000..f4b27817c1 --- /dev/null +++ b/website_recaptcha_v2/views/website_templates.xml @@ -0,0 +1,22 @@ + + + + +