登录
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace app\middleware;
|
||||
|
||||
use app\common\model\User;
|
||||
use app\common\utils\Jwt;
|
||||
use ReflectionClass;
|
||||
use Webman\MiddlewareInterface;
|
||||
@@ -22,7 +23,8 @@ class AuthCheck implements MiddlewareInterface
|
||||
} else {
|
||||
try {
|
||||
$authHeader = $request->header('Fdesk-Auth-Token');
|
||||
if (!$authHeader || !preg_match('/Bearer\s(\S+)/', $authHeader, $matches)) {
|
||||
$user = User::where('union_id',$authHeader)->first();
|
||||
if (!$user) {
|
||||
$body = [
|
||||
'status' => 'fail',
|
||||
'code' => 401,
|
||||
@@ -31,8 +33,7 @@ class AuthCheck implements MiddlewareInterface
|
||||
];
|
||||
return response(json_encode($body, JSON_UNESCAPED_UNICODE), 401, ['Content-Type' => 'application/json']);
|
||||
}
|
||||
$token = $matches[1];
|
||||
$request->user = (new Jwt())->verifyToken($token);
|
||||
$request->user = $user;
|
||||
return $handler($request);
|
||||
} catch (\Throwable $e) {
|
||||
$body = [
|
||||
|
||||
Reference in New Issue
Block a user