]> _ Git - fluidbook-html5.git/commitdiff
wip #5036 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 17 Jan 2022 19:20:53 +0000 (20:20 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 17 Jan 2022 19:20:53 +0000 (20:20 +0100)
js/libs/fluidbook/fluidbook.loader.js
js/libs/fluidbook/fluidbook.secure.js

index 1d173118b31c40b37a020532dc4cc20fe77c6675..5e7e54426728889050e6c3b623d050dbb08c99be 100644 (file)
@@ -156,6 +156,18 @@ FluidbookLoader.prototype = {
     },
 
     _preloadPage: function (page, callback) {
+        var $this = this;
+        var _cb = function (data) {
+            $this._preloadPageAfterSecurityChecks(page, callback);
+        };
+        if (this.fluidbook.settings.recaptcha) {
+            this.fluidbook.secure.recaptcha('loadpage', _cb);
+            return;
+        }
+        _cb();
+    },
+
+    _preloadPageAfterSecurityChecks: function (page, callback) {
         if (page == undefined || page == 'undefined' || page > this.fluidbook.contentlock.getMaxPage() || page < 1) {
             callback();
             return;
@@ -269,8 +281,7 @@ FluidbookLoader.prototype = {
         }
 
         $("#loadedcontents [data-page='" + page + "']").remove();
-    },
-    setContentsInDoublePage: function (doublePage, pages, immediate, callback) {
+    }, setContentsInDoublePage: function (doublePage, pages, immediate, callback) {
         var $this = this;
 
         var leftPage = pages[0];
@@ -290,8 +301,8 @@ FluidbookLoader.prototype = {
                 });
             });
         }
-    },
-    loadPage: function (pageNr, doublePage, position, callback) {
+    }, loadPage: function (pageNr, doublePage, position, callback) {
+
         if (pageNr <= 0 || pageNr > this.fluidbook.settings.pages) {
             callback();
             return;
@@ -384,24 +395,21 @@ FluidbookLoader.prototype = {
 
     loadPageShade: function (position) {
         return this.loadImage('images/shadows/pages/' + position + '.png', this.fluidbook.settings.width / 4, this.fluidbook.settings.height);
-    },
-    loadLeftPage: function (page, doublePage, callback) {
+    }, loadLeftPage: function (page, doublePage, callback) {
         if (page > 0 && page <= this.fluidbook.contentlock.getMaxPage()) {
             this.loadPage(page, doublePage, 'left', callback);
         } else {
             $(doublePage).find('.left').remove();
             callback();
         }
-    },
-    loadRightPage: function (page, doublePage, callback) {
+    }, loadRightPage: function (page, doublePage, callback) {
         if (!this.fluidbook.displayOnePage && page <= this.fluidbook.contentlock.getMaxPage() && page > 0) {
             this.loadPage(page, doublePage, 'right', callback);
         } else {
             $(doublePage).find('.right').remove();
             callback();
         }
-    },
-    getBackgroundURL: function (page) {
+    }, getBackgroundURL: function (page) {
         var version = this.getVersionToLoad(page);
         if (version === 'vector') {
             return false;
@@ -412,8 +420,7 @@ FluidbookLoader.prototype = {
 
     getTextsURL: function (page) {
         return 'data/contents/p' + page + '.svg';
-    },
-    setBackground: function (page, callback) {
+    }, setBackground: function (page, callback) {
         var $this = this;
         var back = $("#page_" + page + ' .background');
         this._loadBackground(page, function () {
@@ -421,16 +428,14 @@ FluidbookLoader.prototype = {
             $(back).append($this.backgrounds[page]);
             callback();
         });
-    },
-    setOnStage: function (element) {
+    }, setOnStage: function (element) {
         if (element === undefined || element == null) {
             return;
         }
         if (!isOnStage(element)) {
             $("#loadedcontents").append($(element));
         }
-    },
-    _loadBackground: function (page, callback) {
+    }, _loadBackground: function (page, callback) {
         if (page <= 0 || page > this.fluidbook.settings.pages) {
             callback();
             return;
@@ -447,8 +452,7 @@ FluidbookLoader.prototype = {
                 this.__loadBackground(page, callback);
             }
         }
-    },
-    __loadBackground: function (page, callback) {
+    }, __loadBackground: function (page, callback) {
         if (page <= 0 || page > this.fluidbook.settings.pages) {
             callback();
             return;
@@ -459,8 +463,7 @@ FluidbookLoader.prototype = {
             return false;
         }
         this.backgrounds[page] = this.loadImage(url, null, null, null, page, callback);
-    },
-    needSeparateTextures: function (page) {
+    }, needSeparateTextures: function (page) {
         if (this._needSeparateTextures[page] === undefined) {
             var $this = this;
             this._needSeparateTextures[page] = false;
@@ -477,8 +480,7 @@ FluidbookLoader.prototype = {
             });
         }
         return this._needSeparateTextures[page];
-    },
-    loadTexture: function (page, callback, enter) {
+    }, loadTexture: function (page, callback, enter) {
         if (enter === undefined) {
             enter = true;
         }
@@ -491,10 +493,7 @@ FluidbookLoader.prototype = {
         }
 
 
-        if (
-            (enter && this.textures[page] !== undefined && this.textures[page] !== null) ||
-            (!enter && this.leaveTextures[page] !== undefined && this.leaveTextures[page] !== null)
-        ) {
+        if ((enter && this.textures[page] !== undefined && this.textures[page] !== null) || (!enter && this.leaveTextures[page] !== undefined && this.leaveTextures[page] !== null)) {
             callback();
         } else {
             try {
@@ -818,8 +817,7 @@ FluidbookLoader.prototype = {
         var url = this.getTextsURL(pageNr);
         if (this.fluidbook.support.svgtocanvg) {
             $.ajax({
-                url: url,
-                dataType: 'text',
+                url: url, dataType: 'text',
             }).done(function (data) {
                 $this.texts[pageNr] = data;
                 callback();
@@ -827,16 +825,14 @@ FluidbookLoader.prototype = {
         } else {
             this.texts[pageNr] = this.loadImage(url, null, null, 'image/svg+xml', pageNr, callback);
         }
-    },
-    loadDatas: function (pageNr, callback) {
+    }, loadDatas: function (pageNr, callback) {
         var $this = this;
         this.loadTexts(pageNr, function () {
             $this.setBackground(pageNr, function () {
                 callback();
             });
         });
-    },
-    getImage: function (src, width, height, type, callback) {
+    }, getImage: function (src, width, height, type, callback) {
         var img = this.loadImage(src, width, height, type, null, callback);
         return $(img).get(0).outerHTML;
     },
index d9d26a6cd15d909a2327fa55ef315eefa5cd0f6e..ed5acfc5616ed8371d1485d02475fba282dcc1ed 100644 (file)
@@ -1,10 +1,17 @@
 function FluidbookSecure(fluidbook) {
     this.fluidbook = fluidbook;
+    this.serverSideRecaptcha = true;
+    this.lastRecaptchaCall = 0;
     this.init();
 }
 
 FluidbookSecure.prototype = {
     init: function () {
+        if (this.fluidbook.settings.recaptcha) {
+            this.recaptcha('load', function () {
+
+            });
+        }
         if (this.fluidbook.settings.restrictPrintDownload !== '') {
             if (window.location.search.indexOf(this.fluidbook.settings.restrictPrintDownload) === -1) {
                 if (this.fluidbook.settings.restrictPrint) {
@@ -21,6 +28,40 @@ FluidbookSecure.prototype = {
         }
     },
 
+    recaptcha: function (action, callback) {
+        var now = Date.now();
+        var limit = now - 60000;
+        if (this.lastRecaptchaCall > limit) {
+            callback();
+            return;
+        }
+        this.lastRecaptchaCall = now;
+
+        var $this = this;
+        try {
+            grecaptcha.ready(function () {
+                grecaptcha.execute(this.fluidbook.settings.recaptcha, {action: action}).then(function (token) {
+                    if ($this.serverSideRecaptcha) {
+                        $.ajax({
+                            method: 'post',
+                            url: '_recaptcha.php',
+                            data: {token: token},
+                            complete: callback,
+                            error: function (data) {
+                                $this.serverSideRecaptcha = false;
+                                callback();
+                            },
+                        });
+                    } else {
+                        callback();
+                    }
+                });
+            });
+        } catch (e) {
+            callback();
+        }
+    },
+
     checkSecure: function (callback) {
         if (this.fluidbook.settings.secureURL !== 'http://' && this.fluidbook.settings.secureURL !== '') {
             return this.checkSecureByURL(callback);
@@ -35,14 +76,9 @@ FluidbookSecure.prototype = {
     checkSecureByURL: function (callback) {
         var $this = this;
         $.ajax({
-            url: $this.fluidbook.settings.secureURL,
-            crossDomain: true,
-            method: 'GET',
-            type: 'json',
-            xhrFields: {
+            url: $this.fluidbook.settings.secureURL, crossDomain: true, method: 'GET', type: 'json', xhrFields: {
                 withCredentials: true
-            },
-            success: function (data) {
+            }, success: function (data) {
                 var res = data.data[0]['logged-in'];
                 if (res !== undefined && res !== null) {
                     if (res === true) {
@@ -51,8 +87,7 @@ FluidbookSecure.prototype = {
                         $this.secureByURLNOK();
                     }
                 }
-            },
-            error: function (e) {
+            }, error: function (e) {
                 console.log(e);
                 callback();
             }