Files
ulthon_information/app/admin/controller/Login.php
augushong b4558b55fb feat(admin): 为登录功能添加验证码开关配置
- 在环境变量中引入 `captcha_login` 配置项,用于控制登录时是否需要验证码
- 根据配置动态显示或隐藏登录页面的验证码输入框
- 后端登录验证逻辑根据配置决定是否校验验证码
2026-05-01 10:49:22 +08:00

65 lines
1.5 KiB
PHP

<?php
namespace app\admin\controller;
use think\Request;
use think\facade\View;
use think\facade\Validate;
use think\validate\ValidateRule as Rule;
use app\model\Admin;
use think\facade\Session;
class Login extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
View::assign('captcha_login', env('captcha_login', true));
return View::fetch();
}
public function auth()
{
$post_data = $this->request->post();
$validate = Validate::rule('account',Rule::isRequire())
->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());
}
$model_admin = Admin::where('account',$post_data['account'])->find();
if(empty($model_admin)){
return json_message('帐号不存在');
}
if($model_admin->getData('password') !== md5($post_data['password'].$model_admin->getData('salt'))){
return json_message('密码错误');
}
Session::set('admin_id',$model_admin->id);
return json_message();
}
public function logout()
{
Session::clear();
$this->success('已经安全退出','Login/Index');
}
}