You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.6KB

  1. # Copyright 2016-2017 LasLabs Inc.
  2. # Copyright 2019 Simone Orsi - Camptocamp SA
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import json
  5. from odoo import http
  6. from odoo.http import request
  7. from odoo.addons.website_form.controllers.main import WebsiteForm
  8. class WebsiteForm(WebsiteForm):
  9. @http.route(
  10. "/website/recaptcha/",
  11. type="http",
  12. auth="public",
  13. methods=["POST"],
  14. website=True,
  15. multilang=False,
  16. )
  17. def recaptcha_public(self):
  18. recaptcha_model = request.env["website.form.recaptcha"].sudo()
  19. creds = recaptcha_model._get_api_credentials(request.website)
  20. return json.dumps({"site_key": creds["site_key"]})
  21. def extract_data(self, model, values):
  22. """ Inject ReCaptcha validation into pre-existing data extraction """
  23. res = super(WebsiteForm, self).extract_data(model, values)
  24. if model.sudo().website_form_access:
  25. recaptcha_model = request.env["website.form.recaptcha"].sudo()
  26. recaptcha_model._validate_request(request, values)
  27. return res
  28. @http.route(
  29. "/website/recaptcha/form_enabled/<string:model_name>",
  30. type="http",
  31. auth="public",
  32. methods=["POST"],
  33. website=True,
  34. multilang=False,
  35. )
  36. def has_website_form_access(self, model_name):
  37. """Public method to decide whether to hook recaptcha or not"""
  38. return json.dumps(
  39. model_name
  40. in request.env["ir.model"]
  41. .sudo()
  42. .search([("website_form_access", "=", True)])
  43. .mapped("model")
  44. )
上海开阖软件有限公司 沪ICP备12045867号-1