Last active
January 4, 2019 10:38
-
-
Save simahawk/9175606150f682ebc182189b03743354 to your computer and use it in GitHub Desktop.
odoo website recaptcha improvements
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
/* Copyright 2016-2017 LasLabs Inc. | |
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | |
*/ | |
odoo.define('website_form_recaptcha.recaptcha', function (require) { | |
"use strict"; | |
var ajax = require('web.ajax'); | |
var snippet_animation = require('website.content.snippets.animation'); | |
var form_builder_send = snippet_animation.registry.form_builder_send; | |
snippet_animation.registry.form_builder_send = form_builder_send.extend({ | |
start: function () { | |
var self = this; | |
this._super(); | |
this.$captchas = self.$('.o_website_form_recaptcha'); | |
this.handle_captcha(); | |
}, | |
handle_captcha: function() { | |
return ajax.post('/website/recaptcha/', {}).then( | |
function (result) { | |
var data = JSON.parse(result); | |
self.$captchas.append(this._get_captcha_elem(data)); | |
if (self.$captchas.length) { | |
$.getScript(self._get_captcha_script_url(data)); | |
} | |
} | |
); | |
}, | |
_get_captcha_elem: function (data) { | |
return $('div', { | |
'class': 'g-recaptcha', | |
'data-sitekey': data.site_key | |
}); | |
}, | |
_get_captcha_script_url: function (data) { | |
# TODO: interpolate lang if present in session.user_context | |
return 'https://www.google.com/recaptcha/api.js' | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment