增加极验验证开关设置
This commit is contained in:
+126
-54
@@ -156,7 +156,7 @@
|
||||
<div class="layui-tab">
|
||||
<ul class="layui-tab-title">
|
||||
<li class="layui-this" lay-id="account">账密登录</li>
|
||||
<li lay-id="phone">手机验证码</li>
|
||||
<!-- <li lay-id="phone">手机验证码</li> -->
|
||||
<li lay-id="wechat">微信登录</li>
|
||||
</ul>
|
||||
<div class="layui-tab-content">
|
||||
@@ -189,7 +189,7 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="layui-tab-item" id="phone">
|
||||
<!-- <div class="layui-tab-item" id="phone">
|
||||
<form action="#" method="post" class="layui-form login-form">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block" style="margin-left: 0;">
|
||||
@@ -217,7 +217,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="layui-tab-item" id="wechat">
|
||||
<div class="wechat-login">
|
||||
<img src="" alt="微信登录" class="layui-img">
|
||||
@@ -233,25 +233,131 @@
|
||||
var element = layui.element;
|
||||
var $ = layui.jquery;
|
||||
|
||||
// 初始化极验验证
|
||||
var handler = function (captchaObj) {
|
||||
// 将验证码渲染到指定容器
|
||||
captchaObj.appendTo('#gt-captcha');
|
||||
// 检查极验验证是否开启
|
||||
<?php if ($config['geetest_open'] == 1): ?>
|
||||
// 初始化极验验证
|
||||
var handler = function (captchaObj) {
|
||||
// 将验证码渲染到指定容器
|
||||
captchaObj.appendTo('#gt-captcha');
|
||||
|
||||
// 账密登录表单提交
|
||||
form.on('submit(accountLogin)', function (data) {
|
||||
var validate = captchaObj.getValidate();
|
||||
if (!validate) {
|
||||
layer.msg('请完成验证码验证', {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
// 账密登录表单提交
|
||||
form.on('submit(accountLogin)', function (data) {
|
||||
var validate = captchaObj.getValidate();
|
||||
if (!validate) {
|
||||
layer.msg('请完成验证码验证', {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
data.field.geetest_challenge = validate.geetest_challenge;
|
||||
data.field.geetest_validate = validate.geetest_validate;
|
||||
data.field.geetest_seccode = validate.geetest_seccode;
|
||||
|
||||
$.ajax({
|
||||
url: '{:url("index/user/login")}',
|
||||
type: 'POST',
|
||||
data: data.field,
|
||||
dataType: 'json',
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
// 存储登录数据,设置7天过期
|
||||
var expireTime = new Date().getTime() + 7 * 24 * 60 * 60 * 1000;
|
||||
localStorage.setItem('user_account', data.field.account);
|
||||
localStorage.setItem('user_password', btoa(data.field.password));
|
||||
localStorage.setItem('expire_time', expireTime);
|
||||
// 添加登录状态标记
|
||||
localStorage.setItem('is_auto_login', 'true');
|
||||
|
||||
layer.msg('登录成功', {
|
||||
icon: 1,
|
||||
time: 2000,
|
||||
shade: 0.3
|
||||
}, function () {
|
||||
window.location.href = '{:url("/")}';
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
data.field.geetest_challenge = validate.geetest_challenge;
|
||||
data.field.geetest_validate = validate.geetest_validate;
|
||||
data.field.geetest_seccode = validate.geetest_seccode;
|
||||
});
|
||||
|
||||
// 手机验证码登录表单提交
|
||||
form.on('submit(phoneLogin)', function (data) {
|
||||
var validate = captchaObj.getValidate();
|
||||
if (!validate) {
|
||||
layer.msg('请完成验证码验证', {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
data.field.geetest_challenge = validate.geetest_challenge;
|
||||
data.field.geetest_validate = validate.geetest_validate;
|
||||
data.field.geetest_seccode = validate.geetest_seccode;
|
||||
|
||||
$.ajax({
|
||||
url: '{:url("index/user/login")}',
|
||||
type: 'POST',
|
||||
data: data.field,
|
||||
dataType: 'json',
|
||||
success: function (res) {
|
||||
if (res.code === 0) {
|
||||
layer.msg('登录成功', {
|
||||
icon: 1,
|
||||
time: 2000,
|
||||
shade: 0.3
|
||||
}, function () {
|
||||
window.location.href = '{:url("/")}';
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
// 点击获取验证码按钮时验证
|
||||
document.getElementById('getCode').addEventListener('click', function () {
|
||||
var validate = captchaObj.getValidate();
|
||||
if (!validate) {
|
||||
layer.msg('请完成验证码验证', {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.log('获取验证码');
|
||||
});
|
||||
};
|
||||
|
||||
// 直接使用配置初始化极验验证,并添加错误处理
|
||||
initGeetest4({
|
||||
captchaId: '{$config[\'geetest_id\']}',
|
||||
offline: false,
|
||||
new_captcha: true
|
||||
}, handler, function (error) {
|
||||
console.error('极验验证初始化失败:', error);
|
||||
layer.msg('验证码初始化失败,请刷新页面重试', {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
});
|
||||
});
|
||||
<?php else: ?>
|
||||
// 极验验证关闭,移除验证码容器
|
||||
$('#gt-captcha').remove();
|
||||
|
||||
// 移除表单提交时的验证码验证逻辑
|
||||
form.on('submit(accountLogin)', function (data) {
|
||||
$.ajax({
|
||||
url: '{:url("index/user/login")}',
|
||||
type: 'POST',
|
||||
@@ -285,20 +391,7 @@
|
||||
return false;
|
||||
});
|
||||
|
||||
// 手机验证码登录表单提交
|
||||
form.on('submit(phoneLogin)', function (data) {
|
||||
var validate = captchaObj.getValidate();
|
||||
if (!validate) {
|
||||
layer.msg('请完成验证码验证', {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
});
|
||||
return false;
|
||||
}
|
||||
data.field.geetest_challenge = validate.geetest_challenge;
|
||||
data.field.geetest_validate = validate.geetest_validate;
|
||||
data.field.geetest_seccode = validate.geetest_seccode;
|
||||
|
||||
$.ajax({
|
||||
url: '{:url("index/user/login")}',
|
||||
type: 'POST',
|
||||
@@ -324,32 +417,11 @@
|
||||
return false;
|
||||
});
|
||||
|
||||
// 点击获取验证码按钮时验证
|
||||
// 移除获取验证码按钮的验证码验证逻辑
|
||||
document.getElementById('getCode').addEventListener('click', function () {
|
||||
var validate = captchaObj.getValidate();
|
||||
if (!validate) {
|
||||
layer.msg('请完成验证码验证', {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.log('获取验证码');
|
||||
});
|
||||
};
|
||||
|
||||
// 直接使用配置初始化极验验证,并添加错误处理
|
||||
initGeetest4({
|
||||
captchaId: '{$config[\'geetest_id\']}',
|
||||
offline: false,
|
||||
new_captcha: true
|
||||
}, handler, function (error) {
|
||||
console.error('极验验证初始化失败:', error);
|
||||
layer.msg('验证码初始化失败,请刷新页面重试', {
|
||||
icon: 2,
|
||||
time: 2000
|
||||
});
|
||||
});
|
||||
<?php endif; ?>
|
||||
|
||||
// 页面加载时检查是否有保存的登录数据
|
||||
$(function () {
|
||||
|
||||
Reference in New Issue
Block a user