mirror of
https://github.com/v2board/v2board.git
synced 2025-06-15 22:27:50 +08:00
update: add client token in cache
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user