Skip to content

Commit d22f268

Browse files
committed
check if site key is defined and if recaptcha API is not loaded
1 parent baffa9e commit d22f268

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/modules/security.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@
529529

530530
var setupGooglereCaptcha = function (evt, $forms, config)
531531
{
532+
if( typeof grecaptcha !== typeof undefined ){
533+
throw new Error('reCaptcha API can not be loaded by hand, delete reCaptcha API snippet.');
534+
}
535+
532536
var src = '//www.google.com/recaptcha/api.js?onload=reCaptchaLoaded&render=explicit' + (config.lang ? '&hl=' + config.lang : '');
533537
if ($('body').find('script[src="' + src + '"]').length === 0)
534538
{
@@ -560,13 +564,18 @@
560564
$('[data-validation~="recaptcha"]', $form).each(function ()
561565
{
562566
var $el = $(this),
563-
div = document.createElement('DIV');
567+
div = document.createElement('DIV'),
568+
sitekey = sitekey || $el.valAttr('recaptcha-sitekey');
569+
570+
if( !sitekey ){
571+
throw new Error('Google reCaptcha site key is required.');
572+
}
564573

565574
$el.hide();
566575
$el.parent().append(div);
567576

568577
var widget_id = grecaptcha.render(div, {
569-
sitekey: sitekey || $el.valAttr('recaptcha-sitekey'),
578+
sitekey: sitekey,
570579
theme: theme || $el.valAttr('recaptcha-theme') || 'light'
571580
});
572581

0 commit comments

Comments
 (0)