-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathrecaptcha.phtml
58 lines (52 loc) · 2.03 KB
/
recaptcha.phtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/** @var $block Magento\ReCaptchaUi\Block\ReCaptcha */
$config = $block->getCaptchaUiConfig();
$renderingOptions = $config['rendering'] ?? [];
$isInvisible = !empty($config['invisible']);
?>
<div class="admin__field <?= /* @noEscape */ $isInvisible ? 'field-invisible-recaptcha' : 'field-recaptcha' ?>">
<div id="admin-recaptcha"
class="admin-recaptcha-content<?=
/* @noEscape */ !empty($renderingOptions['size']) ? ' size-' . $renderingOptions['size'] : '' ?>"></div>
</div>
<script>
require([
'jquery'
], function (
$
) {
const element = document.createElement('script');
const scriptTag = document.getElementsByTagName('script')[0];
element.async = true;
element.src = 'https://www.google.com/recaptcha/api.js'
+ '?onload=globalOnRecaptchaOnLoadCallback&render=explicit';
window.globalOnRecaptchaOnLoadCallback = function () {
let token = '';
this.widgetId = grecaptcha.render('admin-recaptcha', {
<?php foreach ($renderingOptions as $key => $value): ?>
'<?= $block->escapeJs($key) ?>': '<?= $block->escapeJs($value) ?>',
<?php endforeach; ?>
'callback': function (token) { // jscs:ignore jsDoc
<?php if ($isInvisible): ?>
this.token = token;
$('#login-form').submit();
<?php endif; ?>
}.bind(this)
});
<?php if ($isInvisible): ?>
$('#login-form').submit(function (event) {
if (!this.token) {
event.preventDefault(event);
event.stopImmediatePropagation();
grecaptcha.execute(this.widgetId);
}
}.bind(this));
<?php endif; ?>
}.bind(this);
scriptTag.parentNode.insertBefore(element, scriptTag);
});
</script>