refactor: 修改登录验证码为可空
This commit is contained in:
@@ -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('验证码错误');
|
||||
}
|
||||
}
|
||||
|
||||
// 验证用户
|
||||
|
||||
@@ -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不能为空'
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user