GEETEST
文档:http://docs.geetest.com/sensebot/apirefer/api/web#onSuccess-callback
背景
实习期间,安全部门提出后台管理系统的登录页面有隐患,要求在发送验证码前加入滑块验证。
实现
主要流程
1 2 3
| <div id="captcha-box"> <div id="loading-tip">加载中,请稍后...</div> </div>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| initGeetest({
product: 'float' }, function (captchaObj) { captchaObj.appendTo("#captchaBox"); captchaObj.onReady(function(){ document.getElementById('loading-tip').style.display = 'none'; }).onSuccess(function(){ const result = captchaObj.getValidate();
ajax('/api/gt-validate', { geetest_challenge: result.geetest_challenge, geetest_validate: result.geetest_validate, geetest_seccode: result.geetest_seccode,
}, function (data) { if (data.status === 'fail') { alert('用户名或密码错误,请重新输入并完成验证'); captchaObj.reset(); }else if(data.status === 'success'){ captchaObj.destroy(); } }); }).onError(function(){ }).onClose(function () { }); });
|