2020-09-19 22:52:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
2022-12-13 12:29:23 +08:00
|
|
|
use App\Services\AuthService;
|
2020-09-19 22:52:05 +08:00
|
|
|
use Closure;
|
|
|
|
|
|
|
|
class Staff
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @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_staff']) 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
|
|
|
]);
|
2020-09-19 22:52:05 +08:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|