From 068234b57c723d4a2cd122c48edfd85d559d15ec Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Wed, 27 Jan 2021 14:01:17 +0800 Subject: [PATCH] =?UTF-8?q?update:auth=E5=A2=9E=E5=8A=A0=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E9=AA=8C=E8=AF=81,=E9=80=82=E9=85=8D?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/CatchAuth.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/extend/catcher/CatchAuth.php b/extend/catcher/CatchAuth.php index 170dfe7..b1d742e 100644 --- a/extend/catcher/CatchAuth.php +++ b/extend/catcher/CatchAuth.php @@ -12,18 +12,30 @@ use think\helper\Str; class CatchAuth { + /** + * @var mixed + */ protected $auth; + /** + * @var mixed + */ protected $guard; // 默认获取 protected $username = 'email'; + // 校验字段 protected $password = 'password'; // 保存用户信息 protected $user = []; + /** + * @var bool + */ + protected $checkPassword = true; + public function __construct() { $this->auth = config('catch.auth'); @@ -54,7 +66,9 @@ class CatchAuth public function attempt($condition) { try { + $user = $this->authenticate($condition); + if (!$user) { throw new LoginFailedException(); } @@ -62,7 +76,7 @@ class CatchAuth 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); } @@ -270,4 +284,17 @@ class CatchAuth return $this; } + + /** + * 忽略密码认证 + * + * @time 2021年01月27日 + * @return $this + */ + public function ignorePasswordVerify(): CatchAuth + { + $this->checkPassword = false; + + return $this; + } }