aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Senko <jakubsenko@gmail.com>2018-02-18 15:04:37 +0100
committerMarc Alexander <admin@m-a-styles.de>2019-09-24 14:03:27 +0200
commit760a03fffc84b625a85d43bacd308cad35a668f0 (patch)
treed7edd54a848bacfef431812a62815db477640136
parenta90f5e6bcc76c06667ca9706de19a5f814a2cbf4 (diff)
downloadforums-760a03fffc84b625a85d43bacd308cad35a668f0.tar
forums-760a03fffc84b625a85d43bacd308cad35a668f0.tar.gz
forums-760a03fffc84b625a85d43bacd308cad35a668f0.tar.bz2
forums-760a03fffc84b625a85d43bacd308cad35a668f0.tar.xz
forums-760a03fffc84b625a85d43bacd308cad35a668f0.zip
[ticket/15564] Switch to Invisible reCAPTCHA
PHPBB3-15564
-rw-r--r--phpBB/assets/javascript/core.js53
-rw-r--r--phpBB/styles/prosilver/template/captcha_recaptcha.html31
2 files changed, 58 insertions, 26 deletions
diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js
index 2ce20a3b1a..c97eb4134a 100644
--- a/phpBB/assets/javascript/core.js
+++ b/phpBB/assets/javascript/core.js
@@ -1650,6 +1650,50 @@ phpbb.lazyLoadAvatars = function loadAvatars() {
});
};
+// reCAPTCHA-related variables
+var recaptcha_form = $('.g-recaptcha').parents('form'),
+ submit_button = null,
+ programatically_submitted = false;
+
+/**
+ * Function is called when reCAPTCHA code is loaded
+ */
+phpbb.recaptchaOnLoad = function() {
+ console.log('ahoj');
+ // listen to submit buttons in order to know which one was pressed
+ $('input[type="submit"]').each(function() {
+ $(this).on('click', function() {
+ submit_button = this;
+ });
+ });
+
+ recaptcha_form.on('submit', function(e) {
+ if (!programatically_submitted) {
+ grecaptcha.execute();
+ e.preventDefault();
+ }
+ });
+}
+
+/**
+ * Function is called after successful solving of reCAPTCHA
+ */
+phpbb.recaptchaOnSubmit = function() {
+ console.log('submit');
+ programatically_submitted = true;
+ // if concrete button was clicked (e.g. preview instead of submit),
+ // let's trigger the same action
+ if (submit_button) {
+ submit_button.click();
+ } else {
+ // rename input[name="submit"] so that we can submit the form
+ if (typeof recaptcha_form.submit !== 'function') {
+ recaptcha_form.submit.name = 'submit_btn';
+ }
+ recaptcha_form.submit();
+ }
+}
+
$(window).on('load', phpbb.lazyLoadAvatars);
/**
@@ -1682,3 +1726,12 @@ $(function() {
});
})(jQuery); // Avoid conflicts with other libraries
+
+// reCAPTCHA doesn't accept callback functions nested inside objects
+// so we need to make this helper functions here
+function phpbbRecaptchaOnLoad() {
+ phpbb.recaptchaOnLoad();
+}
+function phpbbRecaptchaOnSubmit() {
+ phpbb.recaptchaOnSubmit();
+}
diff --git a/phpBB/styles/prosilver/template/captcha_recaptcha.html b/phpBB/styles/prosilver/template/captcha_recaptcha.html
index a123f543a8..8fc7faa50f 100644
--- a/phpBB/styles/prosilver/template/captcha_recaptcha.html
+++ b/phpBB/styles/prosilver/template/captcha_recaptcha.html
@@ -1,30 +1,9 @@
-<!-- IF S_TYPE == 1 -->
-<div class="panel captcha-panel">
- <div class="inner">
-
- <h3 class="captcha-title">{L_CONFIRMATION}</h3>
- <p>{L_CONFIRM_EXPLAIN}</p>
-
- <fieldset class="fields2">
-<!-- ENDIF -->
-
<!-- IF S_RECAPTCHA_AVAILABLE -->
- <dl>
- <dt><label>{L_CONFIRM_CODE}{L_COLON}</label><br /><span>{L_RECAPTCHA_EXPLAIN}</span></dt>
- <dd class="captcha">
- <noscript>
- <div>{L_RECAPTCHA_NOSCRIPT}</div>
- </noscript>
- <script src="{RECAPTCHA_SERVER}.js?hl={LA_RECAPTCHA_LANG}" async defer></script>
- <div class="g-recaptcha" data-sitekey="{RECAPTCHA_PUBKEY}" data-tabindex="<!-- IF $CAPTCHA_TAB_INDEX -->{$CAPTCHA_TAB_INDEX}<!-- ELSE -->10<!-- ENDIF -->"></div>
- </dd>
- </dl>
+ <noscript>
+ <div>{L_RECAPTCHA_NOSCRIPT}</div>
+ </noscript>
+ {% INCLUDEJS RECAPTCHA_SERVER ~ '.js?onload=phpbbRecaptchaOnLoad&hl=' ~ lang('RECAPTCHA_LANG') %}
+ <div class="g-recaptcha" data-sitekey="{RECAPTCHA_PUBKEY}" data-callback="phpbbRecaptchaOnSubmit" data-size="invisible" data-tabindex="<!-- IF $CAPTCHA_TAB_INDEX -->{$CAPTCHA_TAB_INDEX}<!-- ELSE -->10<!-- ENDIF -->"></div>
<!-- ELSE -->
{L_RECAPTCHA_NOT_AVAILABLE}
<!-- ENDIF -->
-
-<!-- IF S_TYPE == 1 -->
- </fieldset>
- </div>
-</div>
-<!-- ENDIF -->