From 16318922b4929c76f17fcb9c5cd31b4fcc830f42 Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Tue, 25 Mar 2025 15:43:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=AA=8C=E8=AF=81=E7=A0=81=E4=B8=BA=E5=8F=AF=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/v1/UserCenter.php | 20 +++++++++++--------- app/admin/validate/v1/LoginValidate.php | 12 ++++++------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/admin/controller/v1/UserCenter.php b/app/admin/controller/v1/UserCenter.php index 5a804929..325c3063 100644 --- a/app/admin/controller/v1/UserCenter.php +++ b/app/admin/controller/v1/UserCenter.php @@ -37,16 +37,18 @@ class UserCenter throw new InvalidLoginException($validate->getError()); } - // 校验验证码 - $code = Cache::get('captcha:token.' . $post['token']); - if (!$code) { - throw new InvalidLoginException('验证码不存在或已过期'); - } - Cache::delete('captcha:token.' . $post['token']); + if (!empty($post['captcha'])) { + // 校验验证码 + $code = Cache::get('captcha:token.' . $post['token']); + if (!$code) { + throw new InvalidLoginException('验证码不存在或已过期'); + } + Cache::delete('captcha:token.' . $post['token']); - // 校验 - if (!password_verify($post['captcha'], $code)) { - throw new InvalidLoginException('验证码错误'); + // 校验 + if (!password_verify($post['captcha'], $code)) { + throw new InvalidLoginException('验证码错误'); + } } // 验证用户 diff --git a/app/admin/validate/v1/LoginValidate.php b/app/admin/validate/v1/LoginValidate.php index 4bf1dd15..847ce654 100644 --- a/app/admin/validate/v1/LoginValidate.php +++ b/app/admin/validate/v1/LoginValidate.php @@ -16,8 +16,8 @@ class LoginValidate extends Validate protected $rule = [ 'username' => 'require', 'password' => 'require', - 'token' => 'require', - 'captcha' => 'require' + 'captcha' => 'max:6', + 'token' => 'requireWith:captcha' ]; /** @@ -27,9 +27,9 @@ class LoginValidate extends Validate * @var array */ protected $message = [ - 'username.require' => '用户名不能为空', - 'password.require' => '密码不能为空', - 'token.require' => '验证码token不能为空', - 'captcha.require' => '验证码不能为空' + 'username.require' => '用户名不能为空', + 'password.require' => '密码不能为空', + 'captcha.captcha' => '验证码不能为空', + 'token.requireWith' => '验证码token不能为空' ]; }