我们正在为企业在线使用odoo 12。 我们想使用Google Recaptcha保护我们的表单。
我们如何实现Google Recaptcha?如果可能的话,请提供一个完整的示例,该示例如何实现。
我们希望使用Recaptcha v3,但如果不可能的话,可以使用v2实现。
当我尝试在线搜索Google Recaptcha的实现时,几乎每次都包含一个.php文件。我们的页面加载了QWeb视图类型,并且不支持php。
是否可以不使用php来实现?我们肯定可以使用html和javascript,甚至可以使用python,是否可以仅使用这些?如果可能的话,我们只希望使用javascript和html来做到这一点,但我认为情况并非如此。
我们可以仅使用html和javascript来实现其他形式保护吗?
答案 0 :(得分:1)
您需要在前端安装reCAPTCHA并在后端实施验证。在文章的底部,我链接了Google reCAPTCHA官方文档。
this.searchTerm$.distinctUntilChanged().combineLatest(
this.selectedLg$.distinctUntilChanged(), (_term, _lg) => {
return {
term: _term,
lg: _lg
}
}
)
.switchMap(t => this.service.search(t.lg, t.term))
.subscribe((results: any[]) => {
this.list= results;
});
前端只需要:
令牌的验证与reCAPTCHA v2中的验证相同。当用户在您的网站上提交表单时,您将获得POST参数<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>
。您需要使用以下参数向Google reCAPTCHA服务发出POST请求。您可以选择自己的HTTP请求框架。
g-recaptcha-response
然后您会从服务获得JSON响应,如果请求失败,则可以在后端处理进一步的操作。
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.
答案 1 :(得分:0)
希望this会有所帮助,您可以从odoo论坛中获得想法。