如何在od中实现recaptcha

2024-05-21 05:59:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我们正在为企业在线使用odoo12。 我们想用google-recaptcha保护我们的表单。你知道吗

我们如何实现google recaptcha?如果可能的话,一个完整的例子如何实现它。你知道吗

我们更喜欢reCAPTCHAv3,但如果不可能,v2实现就可以了。你知道吗

当我尝试在网上搜索google recaptcha的实现时,几乎每次都会包含一个.php文件。我们的页面加载了QWeb视图类型,不支持php。你知道吗

有没有可能在没有php的情况下实现?我们当然可以使用html和javascript,可能还有python,有可能只用这些吗?如果可能的话,我们只想用javascript和html来实现,但我假设不是这样。你知道吗

我们是否可以只使用html和javascript实现其他表单保护?你知道吗


Tags: 文件视图表单odoo12htmlgoogle页面javascript
1条回答
网友
1楼 · 发布于 2024-05-21 05:59:43

Python中的Google reCAPTCHA v3

您需要在前端安装reCAPTCHA,并在后端实现验证。在帖子的底部,我链接了官方的Google reCAPTCHA文档。你知道吗

前端集成

<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>

前端只需要:

  1. 用sitekey加载JavaScript api
  2. 呼叫验证码执行在一个动作中或页面加载时
  3. 将令牌与验证请求一起发送到后端

后端集成

令牌的验证与reCAPTCHA v2中的相同。当用户在您的站点上提交表单时,您将获得POST参数g-recaptcha-response。您需要使用以下参数向Google reCAPTCHA服务发出POST请求。您可以选择您的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.

然后从服务得到一个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
}

来源

相关问题 更多 >