2019-10-29 15:33:36 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
2022-04-10 18:08:26 +08:00
|
|
|
use App\Utils\CacheKey;
|
2019-10-29 15:33:36 +08:00
|
|
|
use Closure;
|
|
|
|
use App\Models\User;
|
2022-04-10 18:08:26 +08:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2019-10-29 15:33:36 +08:00
|
|
|
|
|
|
|
class Client
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
$token = $request->input('token');
|
2022-04-11 10:19:36 +08:00
|
|
|
if (empty($token)) {
|
2019-12-10 10:55:49 +08:00
|
|
|
abort(403, 'token is null');
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
|
|
|
$user = User::where('token', $token)->first();
|
|
|
|
if (!$user) {
|
2019-12-10 10:55:49 +08:00
|
|
|
abort(403, 'token is error');
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
2022-07-11 14:48:35 +08:00
|
|
|
$request->merge([
|
|
|
|
'user' => $user
|
|
|
|
]);
|
2019-10-29 15:33:36 +08:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|