Skip to content

Commit 6af0ba5

Browse files
committed
security-package/issues/205: Added changes for Admin reCAPTCHA. Skip error by Google js,
when API keys of reCAPTCHA is incorrect.
1 parent 00d6d7d commit 6af0ba5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

ReCaptchaUser/view/adminhtml/templates/recaptcha.phtml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
$config = $block->getCaptchaUiConfig();
88
$renderingOptions = $config['rendering'] ?? [];
99
$isInvisible = !empty($config['invisible']);
10+
$isBadgeInline = (isset($renderingOptions['badge']) && $renderingOptions['badge']=='inline') ? true : false;
1011
?>
1112
<div class="admin__field <?= /* @noEscape */ $isInvisible ? 'field-invisible-recaptcha' : 'field-recaptcha' ?>">
1213
<div id="admin-recaptcha"
@@ -45,12 +46,32 @@ $isInvisible = !empty($config['invisible']);
4546
<?php if ($isInvisible): ?>
4647
$('#login-form').submit(function (event) {
4748
if (!this.token) {
49+
<?php if (!$isBadgeInline) : ?>
4850
event.preventDefault(event);
4951
event.stopImmediatePropagation();
5052
grecaptcha.execute(this.widgetId);
53+
<?php else: ?>
54+
this.resultSuccessCallback = false;
55+
let recaptchaResultExecute = grecaptcha.execute(this.widgetId);
56+
recaptchaResultExecute.then(this.successRecaptchaCallback(), this.failureRecaptchaCallback());
57+
if (this.resultSuccessCallback == true) {
58+
event.preventDefault(event);
59+
event.stopImmediatePropagation();
60+
}
61+
<?php endif; ?>
5162
}
5263
}.bind(this));
5364
<?php endif; ?>
65+
66+
<?php if ($isInvisible && $isBadgeInline) : ?>
67+
this.successRecaptchaCallback = function () {
68+
this.resultSuccessCallback = true;
69+
}.bind(this);
70+
71+
this.failureRecaptchaCallback = function () {
72+
}.bind(this);
73+
<?php endif; ?>
74+
5475
}.bind(this);
5576

5677
scriptTag.parentNode.insertBefore(element, scriptTag);

0 commit comments

Comments
 (0)