From 9594d9118b760b05f89aa7f37c4e7859ff32bb54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E9=A3=8E?= Date: Sat, 18 Jan 2025 12:24:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=AA=8C=E8=AF=81=E7=A0=81AP?= =?UTF-8?q?I=E5=B9=B6=E5=90=AF=E7=94=A8API=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/CaptchaController.php | 76 +++++++++++++++++++ .../src/admin/controller/PublicController.php | 12 ++- 2 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 vendor/thinkcmf/cmf-api/src/admin/controller/CaptchaController.php diff --git a/vendor/thinkcmf/cmf-api/src/admin/controller/CaptchaController.php b/vendor/thinkcmf/cmf-api/src/admin/controller/CaptchaController.php new file mode 100644 index 000000000..3d457496b --- /dev/null +++ b/vendor/thinkcmf/cmf-api/src/admin/controller/CaptchaController.php @@ -0,0 +1,76 @@ + 12, + // 验证码图片高度 + 'imageH' => 38, + // 验证码图片宽度 + 'imageW' => 120, + // 验证码位数 + 'length' => 4, + // 背景颜色 + 'bg' => [255, 255, 255], + ]; + $request = request(); + + $fontSize = $request->param('font_size', 12, 'intval'); + if ($fontSize > 8 && $fontSize < 100) { + $config['fontSize'] = $fontSize; + } + + $imageH = $request->param('height', ''); + if ($imageH != '' && $imageH < 100) { + $config['imageH'] = intval($imageH); + } + + $imageW = $request->param('width', ''); + if ($imageW != '' && $imageW < 200) { + $config['imageW'] = intval($imageW); + } + + $length = $request->param('length', 4, 'intval'); + if ($length > 2 && $length <= 100) { + $config['length'] = $length; + } + + $bg = $request->param('bg', ''); + + if (!empty($bg)) { + $bg = explode(',', $bg); + array_walk($bg, 'intval'); + if (count($bg) > 2 && $bg[0] < 256 && $bg[1] < 256 && $bg[2] < 256) { + $config['bg'] = $bg; + } + } + + $id = $request->param('id', 0, 'intval'); + if ($id > 5 || empty($id)) { + $id = ''; + $config['captcha_id'] = $id; + } + + $response = hook_one('captcha_image', $config); + if (empty($response)) { + config($config, 'captcha'); + $response = $captcha->create(null); + } + @ob_clean();// 清除输出缓存 + //直接调用/api/admin/captcha + return $response; + } +} diff --git a/vendor/thinkcmf/cmf-api/src/admin/controller/PublicController.php b/vendor/thinkcmf/cmf-api/src/admin/controller/PublicController.php index 6a340c767..06cacd93e 100644 --- a/vendor/thinkcmf/cmf-api/src/admin/controller/PublicController.php +++ b/vendor/thinkcmf/cmf-api/src/admin/controller/PublicController.php @@ -49,22 +49,28 @@ class PublicController extends RestBaseController */ public function login() { - $this->error('请先使用原来登录页面登录,登录获取token 后再使用后台API'); + //增加验证码功能注释下面一行 + //$this->error('请先使用原来登录页面登录,登录获取token 后再使用后台API'); // TODO 增加最后登录信息记录,如 ip $validate = new \think\Validate(); $validate->rule([ 'username' => 'require', - 'password' => 'require' + 'password' => 'require', + 'captcha' => 'require' ]); $validate->message([ 'username.require' => '请输入手机号,邮箱或用户名!', - 'password.require' => '请输入您的密码!' + 'password.require' => '请输入您的密码!', + 'captcha.require' => '请输入验证码' ]); $data = $this->request->param(); if (!$validate->check($data)) { $this->error($validate->getError()); } + if (!cmf_captcha_check($data['captcha'])) { + $this->error(lang('CAPTCHA_NOT_RIGHT')); + } $userQuery = Db::name("user"); if (Validate::is($data['username'], 'email')) { -- Gitee