From d0f0025560d4ff9d691ff9c04738288886d2f696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20L=C3=B3pez=20Ram=C3=ADrez?= Date: Tue, 30 Jun 2020 18:43:11 +0200 Subject: [PATCH] Feature/optional recaptcha (#109) * Recaptcha option * Captcha showing only if option active * Using website.recaptcha_key_site as active flag * Restored breaklines * Captcha flag set to company * Added vim and Pycharm files to .gitignore * PEP8 in company.py * Missing space * Recaptcha option * Captcha showing only if option active * Using website.recaptcha_key_site as active flag * Restored breaklines * Added vim and Pycharm files to .gitignore * Captcha flag set to company * PEP8 in company.py * Missing space * TODO for overloaded func added * Recaptcha option * Captcha showing only if option active * Using website.recaptcha_key_site as active flag * Restored breaklines * Added vim and Pycharm files to .gitignore * Captcha flag set to company * PEP8 in company.py * Missing space * TODO for overloaded func added * Recaptcha option * Captcha showing only if option active * Restored breaklines * Captcha flag set to company * Removed blank line --- .gitignore | 3 ++ easy_my_coop_website/__init__.py | 1 + easy_my_coop_website/__manifest__.py | 3 +- easy_my_coop_website/controllers/main.py | 45 ++++++++++--------- easy_my_coop_website/models/__init__.py | 1 + easy_my_coop_website/models/company.py | 9 ++++ .../views/res_company_view.xml | 14 ++++++ .../views/subscription_template.xml | 4 ++ 8 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 easy_my_coop_website/models/__init__.py create mode 100644 easy_my_coop_website/models/company.py create mode 100644 easy_my_coop_website/views/res_company_view.xml diff --git a/.gitignore b/.gitignore index 894a44c..03e1a3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.idea/ +*.swp + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/easy_my_coop_website/__init__.py b/easy_my_coop_website/__init__.py index e046e49..91c5580 100644 --- a/easy_my_coop_website/__init__.py +++ b/easy_my_coop_website/__init__.py @@ -1 +1,2 @@ from . import controllers +from . import models diff --git a/easy_my_coop_website/__manifest__.py b/easy_my_coop_website/__manifest__.py index db2f376..c665b87 100644 --- a/easy_my_coop_website/__manifest__.py +++ b/easy_my_coop_website/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Easy My Coop Website", - "version": "12.0.1.0.0", + "version": "12.0.1.0.3", "depends": ["easy_my_coop", "website", "website_recaptcha_reloaded"], "author": "Coop IT Easy SCRLfs", "category": "Cooperative management", @@ -17,6 +17,7 @@ """, "data": [ "views/subscription_template.xml", + "views/res_company_view.xml", "data/website_cooperator_data.xml", ], "installable": True, diff --git a/easy_my_coop_website/controllers/main.py b/easy_my_coop_website/controllers/main.py index ce8ff2e..20e07c4 100644 --- a/easy_my_coop_website/controllers/main.py +++ b/easy_my_coop_website/controllers/main.py @@ -255,30 +255,31 @@ class WebsiteSubscription(http.Controller): is_company = True redirect = "easy_my_coop_website.becomecompanycooperator" email = kwargs.get("company_email") + # TODO: Use a overloaded function with the captcha implementation + if request.website.company_id.captcha_type == 'google': + if ( + "g-recaptcha-response" not in kwargs + or kwargs["g-recaptcha-response"] == "" + ): + values = self.fill_values(values, is_company, logged) + values.update(kwargs) + values["error_msg"] = _( + "the captcha has not been validated," + " please fill in the captcha" + ) - if ( - "g-recaptcha-response" not in kwargs - or kwargs["g-recaptcha-response"] == "" - ): - values = self.fill_values(values, is_company, logged) - values.update(kwargs) - values["error_msg"] = _( - "the captcha has not been validated," - " please fill in the captcha" - ) - - return request.render(redirect, values) - elif not request.website.is_captcha_valid( - kwargs["g-recaptcha-response"] - ): - values = self.fill_values(values, is_company, logged) - values.update(kwargs) - values["error_msg"] = _( - "the captcha has not been validated," - " please fill in the captcha" - ) + return request.render(redirect, values) + elif not request.website.is_captcha_valid( + kwargs["g-recaptcha-response"] + ): + values = self.fill_values(values, is_company, logged) + values.update(kwargs) + values["error_msg"] = _( + "the captcha has not been validated," + " please fill in the captcha" + ) - return request.render(redirect, values) + return request.render(redirect, values) # Check that required field from model subscription_request exists required_fields = sub_req_obj.sudo().get_required_field() diff --git a/easy_my_coop_website/models/__init__.py b/easy_my_coop_website/models/__init__.py new file mode 100644 index 0000000..52e1016 --- /dev/null +++ b/easy_my_coop_website/models/__init__.py @@ -0,0 +1 @@ +from . import company diff --git a/easy_my_coop_website/models/company.py b/easy_my_coop_website/models/company.py new file mode 100644 index 0000000..0474e05 --- /dev/null +++ b/easy_my_coop_website/models/company.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = 'res.company' + captcha_type = fields.Selection([ + ('none', 'Disabled'), + ('google', 'Google Recaptcha'), + ], 'Captcha type or disabled', required=True, default='google') diff --git a/easy_my_coop_website/views/res_company_view.xml b/easy_my_coop_website/views/res_company_view.xml new file mode 100644 index 0000000..8dbce1b --- /dev/null +++ b/easy_my_coop_website/views/res_company_view.xml @@ -0,0 +1,14 @@ + + + + res.company.form.captcha.easymy.coop + + res.company + + + + + + + + diff --git a/easy_my_coop_website/views/subscription_template.xml b/easy_my_coop_website/views/subscription_template.xml index c107440..f12f8b6 100644 --- a/easy_my_coop_website/views/subscription_template.xml +++ b/easy_my_coop_website/views/subscription_template.xml @@ -473,7 +473,9 @@
+

@@ -971,7 +973,9 @@
+