From 3e71e3d47b8209c650b02215fcbf5ab82bceabb7 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 11 Sep 2019 17:51:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=90=8C=E6=AD=A5=E6=BB=91?= =?UTF-8?q?=E5=9D=97=E9=AA=8C=E8=AF=81=E7=A0=81=E8=84=9A=E6=9C=AC=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=8B=BC=E5=9B=BE=E4=B8=8D=E5=9C=A8=E4=B8=80=E6=9D=A1?= =?UTF-8?q?=E7=9B=B4=E7=BA=BF=E4=B8=8A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Issues link https://gitee.com/LongbowEnterprise/SliderCaptcha/issues/I120S1 --- .../lib/captcha/longbow.slidercaptcha.js | 40 +++++++++++++++---- .../lib/captcha/longbow.slidercaptcha.js | 2 +- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/admin/Bootstrap.Admin/wwwroot/lib/captcha/longbow.slidercaptcha.js b/src/admin/Bootstrap.Admin/wwwroot/lib/captcha/longbow.slidercaptcha.js index 8d5d74bf..f42f2f07 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/lib/captcha/longbow.slidercaptcha.js +++ b/src/admin/Bootstrap.Admin/wwwroot/lib/captcha/longbow.slidercaptcha.js @@ -24,7 +24,24 @@ maxLoadCount: 3, localImages: function () { return 'images/Pic' + Math.round(Math.random() * 4) + '.jpg'; - } + }, + verify: function (arr, url) { + var ret = false; + $.ajax({ + url: url, + data: JSON.stringify(arr), + async: false, + cache: false, + type: 'POST', + contentType: 'application/json', + dataType: 'json', + success: function (result) { + ret = result; + } + }); + return ret; + }, + remoteUrl: null }; function Plugin(option) { @@ -153,7 +170,7 @@ var y = that.y - that.options.sliderR * 2 - 1; var ImageData = that.blockCtx.getImageData(that.x - 3, y, L, L); that.block.width = L; - that.blockCtx.putImageData(ImageData, 0, y); + that.blockCtx.putImageData(ImageData, 0, y + 1); that.text.text(that.text.attr('data-text')); }; img.onerror = function () { @@ -273,16 +290,23 @@ }; _proto.verify = function () { - var sum = function (x, y) { return x + y; }; - var square = function (x) { return x * x; }; var arr = this.trail; // 拖动时y轴的移动距离 - var average = arr.reduce(sum) / arr.length; - var deviations = arr.map(function (x) { return x - average; }); - var stddev = Math.sqrt(deviations.map(square).reduce(sum) / arr.length); var left = parseInt(this.block.style.left); + var verified = false; + if (this.options.remoteUrl !== null) { + verified = this.options.verify(arr, this.options.remoteUrl); + } + else { + var sum = function (x, y) { return x + y; }; + var square = function (x) { return x * x; }; + var average = arr.reduce(sum) / arr.length; + var deviations = arr.map(function (x) { return x - average; }); + var stddev = Math.sqrt(deviations.map(square).reduce(sum) / arr.length); + verified = stddev !== 0; + } return { spliced: Math.abs(left - this.x) < this.options.offset, - verified: stddev !== 0 // 简单验证下拖动轨迹,为零时表示Y轴上下没有波动,可能非人为操作 + verified: verified }; }; diff --git a/src/client/Bootstrap.Client/wwwroot/lib/captcha/longbow.slidercaptcha.js b/src/client/Bootstrap.Client/wwwroot/lib/captcha/longbow.slidercaptcha.js index 85774459..f42f2f07 100644 --- a/src/client/Bootstrap.Client/wwwroot/lib/captcha/longbow.slidercaptcha.js +++ b/src/client/Bootstrap.Client/wwwroot/lib/captcha/longbow.slidercaptcha.js @@ -170,7 +170,7 @@ var y = that.y - that.options.sliderR * 2 - 1; var ImageData = that.blockCtx.getImageData(that.x - 3, y, L, L); that.block.width = L; - that.blockCtx.putImageData(ImageData, 0, y); + that.blockCtx.putImageData(ImageData, 0, y + 1); that.text.text(that.text.attr('data-text')); }; img.onerror = function () {