-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zhiyi\Plus\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Contracts\Auth\Guard; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; | ||
|
||
class VerifyUserPassword | ||
{ | ||
/** | ||
* The user guard. | ||
* @var \Illuminate\Contracts\Auth\Guard | ||
*/ | ||
protected $auth; | ||
|
||
/** | ||
* Creates a new instance of the middleware. | ||
* | ||
* @param Guard $auth | ||
*/ | ||
public function __construct(Guard $auth) | ||
{ | ||
$this->auth = $auth; | ||
} | ||
|
||
/** | ||
* The middleware handler. | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException | ||
* @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException | ||
*/ | ||
public function handle(Request $request, Closure $next) | ||
{ | ||
if ($this->auth->guest()) { | ||
throw new UnauthorizedHttpException('请先登录'); | ||
} elseif ($this->auth->getProvider()->validateCredentials( | ||
$this->auth->user(), | ||
[ | ||
'password' => $request->input('password') | ||
] | ||
)) { | ||
return $next($request); | ||
} | ||
|
||
throw new AccessDeniedHttpException('密码验证错误'); | ||
} | ||
} |