-
-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b68a6f2
commit 959c4d8
Showing
10 changed files
with
87 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
import json | ||
|
||
from odoo import http | ||
|
||
from odoo.addons.website.controllers.form import WebsiteForm | ||
from odoo.addons.website_recaptcha_v2_form.controllers.main import BinhexHome | ||
|
||
from .main import BinhexHome | ||
|
||
|
||
class WebsiteRecaptchaForm(WebsiteForm): | ||
@http.route('/website/form/<string:model_name>', type='http', auth="public", methods=['POST'], website=True, | ||
csrf=False) | ||
@http.route( | ||
"/website/form/<string:model_name>", | ||
type="http", | ||
auth="public", | ||
methods=["POST"], | ||
website=True, | ||
csrf=False, | ||
) | ||
def website_form(self, model_name, **kwargs): | ||
if kwargs.get('recaptcha_enabled', False): | ||
if kwargs.get("recaptcha_enabled", False): | ||
valid = BinhexHome.verify_recaptcha_v2(self, values=kwargs) | ||
if not isinstance(valid, bool): | ||
return json.dumps({ | ||
'error': valid, | ||
}) | ||
return json.dumps( | ||
{ | ||
"error": valid, | ||
} | ||
) | ||
return super().website_form(model_name, **kwargs) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import test_recaptcha | ||
from . import test_controller_form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
|
||
from odoo.tests.common import HttpCase | ||
|
||
imp_requests = "odoo.addons.website_recaptcha_v2.models.website.requests" | ||
|
||
|
||
class TestControllerForm(HttpCase): | ||
def open_url_form(self, data=None, url="/website/form/res.partner"): | ||
if not data: | ||
data = { | ||
"recaptcha_enabled": True, | ||
"g-recaptcha": "", | ||
} | ||
res = self.url_open( | ||
url=url, | ||
data=data, | ||
) | ||
return res | ||
|
||
def test_recaptcha_enabled_form(self): | ||
res = self.open_url_form() | ||
recaptcha_not_response = json.loads(res.content.decode("utf-8")) | ||
self.assertEqual( | ||
recaptcha_not_response.get("error"), | ||
"No response given.", | ||
msg=recaptcha_not_response.get("error"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters