diff --git a/setup/website_recaptcha_v2_login/odoo/addons/website_recaptcha_v2_login b/setup/website_recaptcha_v2_login/odoo/addons/website_recaptcha_v2_login new file mode 120000 index 0000000000..4d1d8ca05d --- /dev/null +++ b/setup/website_recaptcha_v2_login/odoo/addons/website_recaptcha_v2_login @@ -0,0 +1 @@ +../../../../website_recaptcha_v2_login \ No newline at end of file diff --git a/setup/website_recaptcha_v2_login/setup.py b/setup/website_recaptcha_v2_login/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_recaptcha_v2_login/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_recaptcha_v2_login/README.rst b/website_recaptcha_v2_login/README.rst new file mode 100644 index 0000000000..31c3b99a1b --- /dev/null +++ b/website_recaptcha_v2_login/README.rst @@ -0,0 +1,91 @@ +==================== +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 +~~~~~~~ + +* Binhex + +Contributors +~~~~~~~~~~~~ + + * Edilio Escalona Almira + * `Binhex `_: + +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_login/__init__.py b/website_recaptcha_v2_login/__init__.py new file mode 100644 index 0000000000..f7209b1710 --- /dev/null +++ b/website_recaptcha_v2_login/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import controllers diff --git a/website_recaptcha_v2_login/__manifest__.py b/website_recaptcha_v2_login/__manifest__.py new file mode 100644 index 0000000000..a35ab15813 --- /dev/null +++ b/website_recaptcha_v2_login/__manifest__.py @@ -0,0 +1,17 @@ +{ + "name": "BINHEX: Website reCAPTCHA v2", + "version": "16.0.1.0.0", + "category": "Website", + "depends": ["web", "website_recaptcha_v2"], + "author": """ + Binhex, + Odoo Community Association (OCA) + """, + "license": "AGPL-3", + "website": "https://github.com/OCA/website", + "summary": "Module to add reCAPTCHA v2 to the login form on the website", + "data": [ + "views/webclient_templates.xml", + ], + "installable": True, +} diff --git a/website_recaptcha_v2_login/controllers/__init__.py b/website_recaptcha_v2_login/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/website_recaptcha_v2_login/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/website_recaptcha_v2_login/controllers/main.py b/website_recaptcha_v2_login/controllers/main.py new file mode 100644 index 0000000000..983c2b0aec --- /dev/null +++ b/website_recaptcha_v2_login/controllers/main.py @@ -0,0 +1,39 @@ +import logging + +from odoo import _, http +from odoo.exceptions import AccessDenied +from odoo.http import request + +from odoo.addons.web.controllers.home import SIGN_UP_REQUEST_PARAMS, Home + +logger = logging.getLogger(__name__) + + +class BinhexHome(Home): + @http.route("/web/login", type="http", auth="none") + def web_login(self, redirect=None, **kw): + Website = request.env["website"].sudo() + values = { + k: v for k, v in request.params.items() if k in SIGN_UP_REQUEST_PARAMS + } + if request.httprequest.method == "POST": + request.env["ir.http"]._auth_method_public() + try: + valid = Website.get_current_website().valid_recaptcha(kw) + if valid: + return super().web_login(redirect, **kw) + except AccessDenied as e: + values.update( + { + "error": str( + e.args[0] + if len(e.args) > 0 + else _("Recaptcha is not valid.") + ) + } + ) + response = request.render("web.login", values) + response.headers["X-Frame-Options"] = "SAMEORIGIN" + response.headers["Content-Security-Policy"] = "frame-ancestors 'self'" + return response + return super().web_login(redirect, **kw) diff --git a/website_recaptcha_v2_login/i18n/es.po b/website_recaptcha_v2_login/i18n/es.po new file mode 100644 index 0000000000..ad619481ec --- /dev/null +++ b/website_recaptcha_v2_login/i18n/es.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * binhex_website_recaptcha_v2 +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-12-02 16:23+0000\n" +"PO-Revision-Date: 2024-12-02 16:23+0000\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: binhex_website_recaptcha_v2 +#. odoo-python +#: code:addons/binhex_website_recaptcha_v2/controllers/main.py:0 +#, python-format +msgid "Recaptcha is not valid." +msgstr "Recaptcha no es vĂ¡lido." + +#. module: binhex_website_recaptcha_v2 +#: model:ir.model,name:binhex_website_recaptcha_v2.model_website +msgid "Website" +msgstr "Sitio web" diff --git a/website_recaptcha_v2_login/models/__init__.py b/website_recaptcha_v2_login/models/__init__.py new file mode 100644 index 0000000000..bd190fa80b --- /dev/null +++ b/website_recaptcha_v2_login/models/__init__.py @@ -0,0 +1 @@ +from . import website diff --git a/website_recaptcha_v2_login/models/website.py b/website_recaptcha_v2_login/models/website.py new file mode 100644 index 0000000000..38ad45c51c --- /dev/null +++ b/website_recaptcha_v2_login/models/website.py @@ -0,0 +1,21 @@ +from odoo import models +from odoo.exceptions import AccessDenied + + +class Website(models.Model): + _inherit = "website" + + # -------------------------------------------------- + # METHODS + # -------------------------------------------------- + """ + Validating that the recaptcha sent is correct + @params: + kw: Data sent from the form + """ + + def valid_recaptcha(self, kw): + valid, message = self.is_recaptcha_v2_valid(kw) + if not valid: + raise AccessDenied(message) + return True diff --git a/website_recaptcha_v2_login/static/description/recaptcha_ico.png b/website_recaptcha_v2_login/static/description/recaptcha_ico.png new file mode 100644 index 0000000000..65f4e0147f Binary files /dev/null and b/website_recaptcha_v2_login/static/description/recaptcha_ico.png differ diff --git a/website_recaptcha_v2_login/views/webclient_templates.xml b/website_recaptcha_v2_login/views/webclient_templates.xml new file mode 100644 index 0000000000..ec30d2926c --- /dev/null +++ b/website_recaptcha_v2_login/views/webclient_templates.xml @@ -0,0 +1,8 @@ + + + +