From 2572c6a3cff26abd18d69e0fa88d034b90d30a68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 22 Aug 2017 16:42:34 +0200 Subject: [PATCH] Add support for invisible captcha in comments see #2242 --- wcfsetup/install/files/js/WCF.Comment.js | 17 +++++++++++++---- .../js/WoltLabSuite/Core/Ui/Comment/Add.js | 17 ++++++++++++++--- .../lib/data/comment/CommentAction.class.php | 1 + 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.Comment.js b/wcfsetup/install/files/js/WCF.Comment.js index 1fdbc6af80..24745ef56c 100644 --- a/wcfsetup/install/files/js/WCF.Comment.js +++ b/wcfsetup/install/files/js/WCF.Comment.js @@ -1105,10 +1105,19 @@ WCF.Comment.Handler = Class.extend({ data: $data }; - $requestData = $.extend(WCF.System.Captcha.getData('commentAdd'), $requestData); - - this._proxy.setOption('data', $requestData); - this._proxy.sendRequest(); + var $captchaData = WCF.System.Captcha.getData('commentAdd'); + if ($captchaData instanceof Promise) { + $captchaData.then($.proxy(function ($captchaData) { + $requestData = $.extend($captchaData, $requestData); + this._proxy.setOption('data', $requestData); + this._proxy.sendRequest(); + }, this)) + } + else { + $requestData = $.extend($captchaData, $requestData); + this._proxy.setOption('data', $requestData); + this._proxy.sendRequest(); + } }, /** diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Comment/Add.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Comment/Add.js index 15072683e6..c167bbb097 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Comment/Add.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Comment/Add.js @@ -102,10 +102,21 @@ define(['Ajax', 'Core', 'EventHandler', 'Language', 'Dom/ChangeListener', 'Dom/U }; if (ControllerCaptcha.has('commentAdd')) { - parameters = Core.extend(parameters, ControllerCaptcha.getData('commentAdd')); + var data = ControllerCaptcha.getData('commentAdd'); + if (data instanceof Promise) { + data.then((function (data) { + parameters = Core.extend(parameters, data); + this._submit(undefined, parameters); + }).bind(this)); + } + else { + parameters = Core.extend(parameters, data); + this._submit(undefined, parameters); + } + } + else { + this._submit(undefined, parameters); } - - this._submit(undefined, parameters); }, /** diff --git a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php index 9ff3939593..4893aa9f5d 100644 --- a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php @@ -902,6 +902,7 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli 'ajaxCaptcha' => true, 'captchaID' => 'commentAdd', 'captchaObjectType' => $captchaObjectType, + 'supportsAsyncCaptcha' => true, 'username' => WCF::getSession()->getVar('username') ]) ]; -- 2.20.1