mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-01 18:32:48 +08:00
feat(admin): 为登录功能添加验证码开关配置
- 在环境变量中引入 `captcha_login` 配置项,用于控制登录时是否需要验证码 - 根据配置动态显示或隐藏登录页面的验证码输入框 - 后端登录验证逻辑根据配置决定是否校验验证码
This commit is contained in:
@@ -18,7 +18,7 @@ class Login extends Common
|
|||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
//
|
View::assign('captcha_login', env('captcha_login', true));
|
||||||
return View::fetch();
|
return View::fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,13 +27,14 @@ class Login extends Common
|
|||||||
{
|
{
|
||||||
$post_data = $this->request->post();
|
$post_data = $this->request->post();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$validate = Validate::rule('account',Rule::isRequire())
|
$validate = Validate::rule('account',Rule::isRequire())
|
||||||
->rule('password',Rule::isRequire())
|
->rule('password',Rule::isRequire());
|
||||||
->rule('captcha',function($value){
|
|
||||||
|
if (env('captcha_login', true)) {
|
||||||
|
$validate->rule('captcha',function($value){
|
||||||
return \captcha_check($value)?true:'验证码错误';
|
return \captcha_check($value)?true:'验证码错误';
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if(!$validate->check($post_data)){
|
if(!$validate->check($post_data)){
|
||||||
return json_message($validate->getError());
|
return json_message($validate->getError());
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
<input type="password" name="password" required lay-verify="required" placeholder="请输入密码" value="" autocomplete="off" class="layui-input">
|
<input type="password" name="password" required lay-verify="required" placeholder="请输入密码" value="" autocomplete="off" class="layui-input">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{if $captcha_login}
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">验证码</label>
|
<label class="layui-form-label">验证码</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
@@ -55,6 +56,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
|
|
||||||
@@ -88,7 +90,9 @@
|
|||||||
location.href = '{:url("admin/Index/index")}'
|
location.href = '{:url("admin/Index/index")}'
|
||||||
}, 1200);
|
}, 1200);
|
||||||
} else {
|
} else {
|
||||||
|
if ($('.captcha').length) {
|
||||||
$('.captcha').click()
|
$('.captcha').click()
|
||||||
|
}
|
||||||
layer.msg(result.msg);
|
layer.msg(result.msg);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user