-
-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
19 changed files
with
1,094 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../website_recaptcha_v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://github.com/OCA/website/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 <https://github.com/OCA/website/issues/new?body=module:%20website_recaptcha_v2%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
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 <https://elico-corp.com>`_: | ||
|
||
* Augustin Cisterne-Kaas | ||
* `Tech Receptives <https://techreceptives.com>`_: | ||
|
||
* Parthiv Patel | ||
* Hardik Kalariya | ||
|
||
* `Coop IT Easy SC <https://coopiteasy.be>`_: | ||
|
||
* 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 <https://github.com/OCA/website/tree/16.0/website_recaptcha_v2>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2010-2014 Elico Corp | ||
# SPDX-FileContributor: Augustin Cisterne-Kaas <[email protected]> | ||
# SPDX-FileCopyrightText: 2015 Tech-Receptives Solutions Pvt. Ltd. | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# SPDX-FileCopyrightText: 2010-2014 Elico Corp | ||
# SPDX-FileContributor: Augustin Cisterne-Kaas <[email protected]> | ||
# 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", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- | ||
SPDX-FileCopyrightText: 2022 Coop IT Easy SC | ||
SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
<odoo> | ||
|
||
<record id="website.default_website" model="website"> | ||
<field name="recaptcha_v2_enabled">True</field> | ||
<!-- | ||
reCAPTCHA test keys from https://developers.google.com/recaptcha/docs/faq | ||
--> | ||
<field | ||
name="recaptcha_v2_site_key" | ||
>6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI</field> | ||
<field | ||
name="recaptcha_v2_secret_key" | ||
>6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "<i class=\"fa fa-arrow-right\"/>\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 "<span class=\"fa fa-lg fa-globe\" title=\"Values set here are website-specific.\" groups=\"website.group_multi_website\"/>" | ||
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 "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# SPDX-FileCopyrightText: 2010-2014 Elico Corp | ||
# SPDX-FileContributor: Augustin Cisterne-Kaas <[email protected]> | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# SPDX-FileCopyrightText: 2010-2014 Elico Corp | ||
# SPDX-FileContributor: Augustin Cisterne-Kaas <[email protected]> | ||
# 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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# SPDX-FileCopyrightText: 2010-2014 Elico Corp | ||
# SPDX-FileContributor: Augustin Cisterne-Kaas <[email protected]> | ||
# 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, "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Oops, something went wrong.