Add support for invisible captcha in comments
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 22 Aug 2017 14:42:34 +0000 (16:42 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 22 Aug 2017 14:42:34 +0000 (16:42 +0200)
see #2242

wcfsetup/install/files/js/WCF.Comment.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Comment/Add.js
wcfsetup/install/files/lib/data/comment/CommentAction.class.php

index 1fdbc6af80e586f733986ac79ae493e045bd746a..24745ef56cf70dca1b2c382a343ecd1daa9380d9 100644 (file)
@@ -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();
+               }
        },
        
        /**
index 15072683e6ff492f726a146a1ce20b2ba226219d..c167bbb0972f89c6a69e7975cbf3c0fec7595408 100644 (file)
@@ -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);
                },
                
                /**
index 9ff393959397fd3dab6465154f94445b98322a0f..4893aa9f5dfd63d6bb569c9bd87b3a2d965f1a22 100644 (file)
@@ -902,6 +902,7 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                                'ajaxCaptcha' => true,
                                'captchaID' => 'commentAdd',
                                'captchaObjectType' => $captchaObjectType,
+                               'supportsAsyncCaptcha' => true,
                                'username' => WCF::getSession()->getVar('username')
                        ])
                ];