Browse Source

Captcha showing only if option active

pull/107/head
César López Ramírez 4 years ago
parent
commit
197a3ba749
  1. 2
      easy_my_coop_website/__manifest__.py
  2. 50
      easy_my_coop_website/controllers/main.py
  3. 2
      easy_my_coop_website/views/subscription_template.xml

2
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",

50
easy_my_coop_website/controllers/main.py

@ -173,7 +173,10 @@ class WebsiteSubscription(http.Controller):
sub_req_obj = request.env["subscription.request"] sub_req_obj = request.env["subscription.request"]
company = request.website.company_id company = request.website.company_id
products = self.get_products_share(is_company) products = self.get_products_share(is_company)
icp_obj = request.env["ir.config_parameter"].sudo()
values["recaptcha_enabled"] = icp_obj.get_param(
"emc_website.captcha_enabled", default="True"
)
if load_from_user: if load_from_user:
values = self.get_values_from_user(values, is_company) values = self.get_values_from_user(values, is_company)
if is_company: if is_company:
@ -245,7 +248,7 @@ class WebsiteSubscription(http.Controller):
def validation(self, kwargs, logged, values, post_file): def validation(self, kwargs, logged, values, post_file):
user_obj = request.env["res.users"] user_obj = request.env["res.users"]
sub_req_obj = request.env["subscription.request"] sub_req_obj = request.env["subscription.request"]
icp_obj = request.env["ir.config_parameter"].sudo()
redirect = "easy_my_coop_website.becomecooperator" redirect = "easy_my_coop_website.becomecooperator"
email = kwargs.get("email") email = kwargs.get("email")
@ -256,29 +259,30 @@ class WebsiteSubscription(http.Controller):
redirect = "easy_my_coop_website.becomecompanycooperator" redirect = "easy_my_coop_website.becomecompanycooperator"
email = kwargs.get("company_email") email = kwargs.get("company_email")
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 icp_obj.get_param('emc_website.captcha_enabled')=="True":
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()

2
easy_my_coop_website/views/subscription_template.xml

@ -473,10 +473,12 @@
<table style="margin-left:195px"> <table style="margin-left:195px">
<tr> <tr>
<td width="80%"> <td width="80%">
<t t-if="recaptcha_enabled == 'True'">
<div class="g-recaptcha" <div class="g-recaptcha"
t-att-data-sitekey="website.recaptcha_key_site" t-att-data-sitekey="website.recaptcha_key_site"
data-theme="green"/> data-theme="green"/>
<br/> <br/>
</t>
</td> </td>
<td> <td>
<div class="form-group"> <div class="form-group">

Loading…
Cancel
Save