update:auth增加忽略密码验证,适配第三方登陆

This commit is contained in:
JaguarJack 2021-01-27 14:01:17 +08:00
parent dc1ce92194
commit 068234b57c

View File

@ -12,18 +12,30 @@ use think\helper\Str;
class CatchAuth class CatchAuth
{ {
/**
* @var mixed
*/
protected $auth; protected $auth;
/**
* @var mixed
*/
protected $guard; protected $guard;
// 默认获取 // 默认获取
protected $username = 'email'; protected $username = 'email';
// 校验字段 // 校验字段
protected $password = 'password'; protected $password = 'password';
// 保存用户信息 // 保存用户信息
protected $user = []; protected $user = [];
/**
* @var bool
*/
protected $checkPassword = true;
public function __construct() public function __construct()
{ {
$this->auth = config('catch.auth'); $this->auth = config('catch.auth');
@ -54,7 +66,9 @@ class CatchAuth
public function attempt($condition) public function attempt($condition)
{ {
try { try {
$user = $this->authenticate($condition); $user = $this->authenticate($condition);
if (!$user) { if (!$user) {
throw new LoginFailedException(); throw new LoginFailedException();
} }
@ -62,7 +76,7 @@ class CatchAuth
throw new LoginFailedException('该用户已被禁用|' . $user->username, Code::USER_FORBIDDEN); throw new LoginFailedException('该用户已被禁用|' . $user->username, Code::USER_FORBIDDEN);
} }
if (!password_verify($condition['password'], $user->password)) { if ($this->checkPassword && !password_verify($condition['password'], $user->password)) {
throw new LoginFailedException('登录失败|' . $user->username); throw new LoginFailedException('登录失败|' . $user->username);
} }
@ -270,4 +284,17 @@ class CatchAuth
return $this; return $this;
} }
/**
* 忽略密码认证
*
* @time 2021年01月27日
* @return $this
*/
public function ignorePasswordVerify(): CatchAuth
{
$this->checkPassword = false;
return $this;
}
} }