feat(admin): 为登录功能添加验证码开关配置

- 在环境变量中引入 `captcha_login` 配置项,用于控制登录时是否需要验证码
- 根据配置动态显示或隐藏登录页面的验证码输入框
- 后端登录验证逻辑根据配置决定是否校验验证码
This commit is contained in:
augushong
2026-05-01 10:49:22 +08:00
parent d1300b8796
commit b4558b55fb
2 changed files with 13 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ class Login extends Common
*/
public function index()
{
//
View::assign('captcha_login', env('captcha_login', true));
return View::fetch();
}
@@ -27,13 +27,14 @@ class Login extends Common
{
$post_data = $this->request->post();
$validate = Validate::rule('account',Rule::isRequire())
->rule('password',Rule::isRequire())
->rule('captcha',function($value){
return \captcha_check($value)?true:'验证码错误';
});
->rule('password',Rule::isRequire());
if (env('captcha_login', true)) {
$validate->rule('captcha',function($value){
return \captcha_check($value)?true:'验证码错误';
});
}
if(!$validate->check($post_data)){
return json_message($validate->getError());

View File

@@ -47,6 +47,7 @@
<input type="password" name="password" required lay-verify="required" placeholder="请输入密码" value="" autocomplete="off" class="layui-input">
</div>
</div>
{if $captcha_login}
<div class="layui-form-item">
<label class="layui-form-label">验证码</label>
<div class="layui-input-block">
@@ -55,6 +56,7 @@
</div>
</div>
{/if}
<div class="layui-form-item">
@@ -88,7 +90,9 @@
location.href = '{:url("admin/Index/index")}'
}, 1200);
} else {
$('.captcha').click()
if ($('.captcha').length) {
$('.captcha').click()
}
layer.msg(result.msg);
}
})