update: add client token in cache

This commit is contained in:
tokumeikoi
2022-04-10 18:08:26 +08:00
parent 447ff0f554
commit e82f28b670
5 changed files with 67 additions and 2 deletions

View File

@ -2,8 +2,10 @@
namespace App\Http\Middleware;
use App\Utils\CacheKey;
use Closure;
use App\Models\User;
use Illuminate\Support\Facades\Cache;
class Client
{
@ -17,7 +19,7 @@ class Client
public function handle($request, Closure $next)
{
$token = $request->input('token');
if (empty($token)) {
if (empty($token) || $this->tokenNotInCache($token)) {
abort(403, 'token is null');
}
$user = User::where('token', $token)->first();
@ -27,4 +29,12 @@ class Client
$request->user = $user;
return $next($request);
}
private function tokenNotInCache($token)
{
// schedule init complete?
if (!Cache::get(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null))) return true;
if (Cache::get(CacheKey::get('SUBSCRIBE_TOKEN', $token))) return false;
return true;
}
}