//引入滑块的 js 文件
var handlerPopup =function (captchaObj) {//成功的回调
captchaObj.onSuccess(function () {var validate =captchaObj.getValidate();
let username= $('#login_user_name').val(); // 要验证的用户名
let password= $('#login_password').val(); // 要验证的密码//账号
$.ajax({
url:"/login/", //进行二次验证(登陆验证),输入验证登陆的用户名和密码的接口
type: "post",async : false,
dataType:"json",
data: {
username: username,
password: password,
csrfmiddlewaretoken:$("[name='csrfmiddlewaretoken']").val(),
geetest_challenge: validate.geetest_challenge,
geetest_validate: validate.geetest_validate,
geetest_seccode: validate.geetest_seccode
},
success: function (data) {
console.log(data) // 返回结果,用户跳转页面或显示错误信息if(data.res){
console.log(data);
location.href=data.url
}else{
$('#user_res').addClass('show_error')
}
}
});
});
$("#login").click(function () {
captchaObj.show();
});//将验证码加到id为captcha的元素里
captchaObj.appendTo("#popup-captcha");//更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
};//滑块显示
$.ajax({
url:"/pc-geetest/register?t=" + (new Date()).getTime(), //加随机数防止缓存
type: "get",
dataType:"json",async : false,
success: function (data) {//使用initGeetest接口//参数1:配置参数//参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
initGeetest({
gt: data.gt,
challenge: data.challenge,
product:"popup", //产品形式,包括:float,embed,popup。注意只对PC版验证码有效
offline: !data.success //表示用户后台检测极验服务器是否宕机,一般不需要关注//更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config
}, handlerPopup);
}
});
})