Skip to content

Commit

Permalink
Feature/optional recaptcha (OCA#109)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cesarlr authored and huguesdk committed Aug 30, 2023
1 parent 3bda99d commit 60b8007
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 23 deletions.
1 change: 1 addition & 0 deletions easy_my_coop_website/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import controllers
from . import models
3 changes: 2 additions & 1 deletion easy_my_coop_website/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -17,6 +17,7 @@
""",
"data": [
"views/subscription_template.xml",
"views/res_company_view.xml",
"data/website_cooperator_data.xml",
],
"installable": True,
Expand Down
45 changes: 23 additions & 22 deletions easy_my_coop_website/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,30 +255,31 @@ def validation(self, kwargs, logged, values, post_file):
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()
Expand Down
1 change: 1 addition & 0 deletions easy_my_coop_website/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import company
9 changes: 9 additions & 0 deletions easy_my_coop_website/models/company.py
Original file line number Diff line number Diff line change
@@ -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')
14 changes: 14 additions & 0 deletions easy_my_coop_website/views/res_company_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record model="ir.ui.view" id="view_company_inherit_captcha">
<field name="name">res.company.form.captcha.easymy.coop</field>
<field name="inherit_id" ref="easy_my_coop.view_company_inherit_form2"/>
<field name="model">res.company</field>
<field name="arch" type="xml">
<field name="internal_rules_approval_text" position="after">
<field name="captcha_type"/>
</field>
</field>
</record>
</odoo>

4 changes: 4 additions & 0 deletions easy_my_coop_website/views/subscription_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@
<table style="margin-left:195px">
<tr>
<td width="80%">
<!-- TODO: Use a overloaded function with the captcha implementation !-->
<div class="g-recaptcha"
t-if="website.company_id.captcha_type == 'google'"
t-att-data-sitekey="website.recaptcha_key_site"
data-theme="green"/>
<br/>
Expand Down Expand Up @@ -971,7 +973,9 @@
<table style="margin-left:195px">
<tr>
<td width="80%">
<!-- TODO: Use a overloaded function with the captcha implementation !-->
<div class="g-recaptcha"
t-if="website.company_id.captcha_type == 'google'"
t-att-data-sitekey="website.recaptcha_key_site"
data-theme="green"/>
<br/>
Expand Down

0 comments on commit 60b8007

Please sign in to comment.