refactor: 修改登录验证码为可空

This commit is contained in:
2025-03-25 15:43:00 +08:00
parent 915dc2fdb2
commit f19927ca33
2 changed files with 17 additions and 15 deletions

View File

@@ -37,6 +37,7 @@ class UserCenter
throw new InvalidLoginException($validate->getError());
}
if (!empty($post['captcha'])) {
// 校验验证码
$code = Cache::get('captcha:token.' . $post['token']);
if (!$code) {
@@ -48,6 +49,7 @@ class UserCenter
if (!password_verify($post['captcha'], $code)) {
throw new InvalidLoginException('验证码错误');
}
}
// 验证用户
$user = SysUserModel::usernameOrMobile($post['username'])->find();

View File

@@ -16,8 +16,8 @@ class LoginValidate extends Validate
protected $rule = [
'username' => 'require',
'password' => 'require',
'token' => 'require',
'captcha' => 'require'
'captcha' => 'max:6',
'token' => 'requireWith:captcha'
];
/**
@@ -29,7 +29,7 @@ class LoginValidate extends Validate
protected $message = [
'username.require' => '用户名不能为空',
'password.require' => '密码不能为空',
'token.require' => '验证码token不能为空',
'captcha.require' => '验证码不能为空'
'captcha.captcha' => '验证码不能为空',
'token.requireWith' => '验证码token不能为空'
];
}