2019-10-29 15:33:36 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
2022-12-13 12:29:23 +08:00
|
|
|
use App\Services\AuthService;
|
2019-10-29 15:33:36 +08:00
|
|
|
use Closure;
|
2022-07-19 03:11:36 +08:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2019-10-29 15:33:36 +08:00
|
|
|
|
|
|
|
class Admin
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2020-01-11 13:36:52 +08:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
2019-10-29 15:33:36 +08:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
2022-07-11 14:48:35 +08:00
|
|
|
$authorization = $request->input('auth_data') ?? $request->header('authorization');
|
|
|
|
if (!$authorization) abort(403, '未登录或登陆已过期');
|
|
|
|
|
2022-12-13 12:29:23 +08:00
|
|
|
$user = AuthService::decryptAuthData($authorization);
|
|
|
|
if (!$user || !$user['is_admin']) abort(403, '未登录或登陆已过期');
|
2022-07-11 14:48:35 +08:00
|
|
|
$request->merge([
|
2022-12-13 12:29:23 +08:00
|
|
|
'user' => $user
|
2022-07-11 14:48:35 +08:00
|
|
|
]);
|
2019-10-29 15:33:36 +08:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|