简体   繁体   English

如何在odoo中实现recaptcha

[英]How to implement recaptcha in odoo

We are using odoo 12 online for enterprises.我们正在为企业在线使用odoo 12。 We would like to protect our forms using google recaptcha.我们希望使用 google recaptcha 保护我们的表单。

How can we implement google recaptcha?我们如何实施 google recaptcha? If possible a full example how to implement it.如果可能的话,一个完整的例子如何实现它。

We would prefer recaptcha v3 but if not possible a v2 implementation is fine.我们更喜欢 recaptcha v3,但如果不可能,v2 实现也可以。

When I try to search online for implementation of google recaptcha there's almost every time a .php file included.当我尝试在线搜索 google recaptcha 的实现时,几乎每次都包含一个 .php 文件。 Our pages are loaded with QWeb view types and php isn't supported.我们的页面加载了 QWeb 视图类型,不支持 php。

Is it possible to implement without php?没有php可以实现吗? We could definitely use html and javascript and probably python, is it possible to do with only these?我们绝对可以使用 html 和 javascript 以及可能使用 python,是否可以只使用这些? If it's possible we would like to do it with only javascript and html but I'm assuming that's not the case.如果可能的话,我们只想用 javascript 和 html 来做,但我认为情况并非如此。

Is there any other form protection we could implement using only html and javascript?我们可以仅使用 html 和 javascript 来实现其他形式的保护吗?

Google reCAPTCHA v3 in Python Python 中的 Google reCAPTCHA v3

You need to install reCAPTCHA on the frontend and implement the verification on the backend.您需要在前端安装 reCAPTCHA 并在后端实现验证。 At the bottom of the post, I linked the official Google reCAPTCHA documentation.在帖子的底部,我链接了官方的 Google reCAPTCHA 文档。

Frontend Integration前端集成

<script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key"></script>
<script>
grecaptcha.ready(function() {
    grecaptcha.execute('reCAPTCHA_site_key', {action: 'homepage'}).then(function(token) {
       ...
    });
});
</script>

The frontend just needs to:前端只需要:

  1. Load the JavaScript api with your sitekey使用您的站点密钥加载 JavaScript api
  2. Call grecaptcha.execute on an action or when the page loads在操作或页面加载时调用 grecaptcha.execute
  3. Send the token to your backend with the request to verify将令牌与验证请求一起发送到您的后端

Backend Integration后端集成

The verification of the token is the same as in reCAPTCHA v2.令牌的验证与 reCAPTCHA v2 中的相同。 When the user submits the form on your site, you get the POST parameter g-recaptcha-response .当用户在您的网站上提交表单时,您将获得 POST 参数g-recaptcha-response You need to make a POST request to the Google reCAPTCHA service with following parameters.您需要使用以下参数向 Google reCAPTCHA 服务发出 POST 请求。 You can take your HTTP request framework of your choice.您可以选择自己的 HTTP 请求框架。

POST Parameter  Description
secret          Required. The shared key between your site and reCAPTCHA.
response        Required. The user response token provided by the reCAPTCHA client-side integration on your site.
remoteip        Optional. The user's IP address.

Then you get a JSON response from the service and if the request failed, you can handle further actions on the backend.然后您会从服务获得 JSON 响应,如果请求失败,您可以在后端处理进一步的操作。

{
  "success": true|false,
  "challenge_ts": timestamp,  // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
  "hostname": string,         // the hostname of the site where the reCAPTCHA was solved
  "error-codes": [...]        // optional
}

Sources来源

希望会有所帮助,您可以从 odoo 论坛中获得想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM