Browse Source

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
pull/73/head
César López Ramírez 4 years ago
committed by GitHub
parent
commit
d0f0025560
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .gitignore
  2. 1
      easy_my_coop_website/__init__.py
  3. 3
      easy_my_coop_website/__manifest__.py
  4. 45
      easy_my_coop_website/controllers/main.py
  5. 1
      easy_my_coop_website/models/__init__.py
  6. 9
      easy_my_coop_website/models/company.py
  7. 14
      easy_my_coop_website/views/res_company_view.xml
  8. 4
      easy_my_coop_website/views/subscription_template.xml

3
.gitignore

@ -1,3 +1,6 @@
.idea/
*.swp
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]

1
easy_my_coop_website/__init__.py

@ -1 +1,2 @@
from . import controllers from . import controllers
from . import models

3
easy_my_coop_website/__manifest__.py

@ -5,7 +5,7 @@
{ {
"name": "Easy My Coop Website", "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"], "depends": ["easy_my_coop", "website", "website_recaptcha_reloaded"],
"author": "Coop IT Easy SCRLfs", "author": "Coop IT Easy SCRLfs",
"category": "Cooperative management", "category": "Cooperative management",
@ -17,6 +17,7 @@
""", """,
"data": [ "data": [
"views/subscription_template.xml", "views/subscription_template.xml",
"views/res_company_view.xml",
"data/website_cooperator_data.xml", "data/website_cooperator_data.xml",
], ],
"installable": True, "installable": True,

45
easy_my_coop_website/controllers/main.py

@ -255,30 +255,31 @@ class WebsiteSubscription(http.Controller):
is_company = True is_company = True
redirect = "easy_my_coop_website.becomecompanycooperator" redirect = "easy_my_coop_website.becomecompanycooperator"
email = kwargs.get("company_email") 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 # Check that required field from model subscription_request exists
required_fields = sub_req_obj.sudo().get_required_field() required_fields = sub_req_obj.sudo().get_required_field()

1
easy_my_coop_website/models/__init__.py

@ -0,0 +1 @@
from . import company

9
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')

14
easy_my_coop_website/views/res_company_view.xml

@ -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
easy_my_coop_website/views/subscription_template.xml

@ -473,7 +473,9 @@
<table style="margin-left:195px"> <table style="margin-left:195px">
<tr> <tr>
<td width="80%"> <td width="80%">
<!-- TODO: Use a overloaded function with the captcha implementation !-->
<div class="g-recaptcha" <div class="g-recaptcha"
t-if="website.company_id.captcha_type == 'google'"
t-att-data-sitekey="website.recaptcha_key_site" t-att-data-sitekey="website.recaptcha_key_site"
data-theme="green"/> data-theme="green"/>
<br/> <br/>
@ -971,7 +973,9 @@
<table style="margin-left:195px"> <table style="margin-left:195px">
<tr> <tr>
<td width="80%"> <td width="80%">
<!-- TODO: Use a overloaded function with the captcha implementation !-->
<div class="g-recaptcha" <div class="g-recaptcha"
t-if="website.company_id.captcha_type == 'google'"
t-att-data-sitekey="website.recaptcha_key_site" t-att-data-sitekey="website.recaptcha_key_site"
data-theme="green"/> data-theme="green"/>
<br/> <br/>

Loading…
Cancel
Save