mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	update: rollback token cache
This commit is contained in:
		| @@ -1,49 +0,0 @@ | |||||||
| <?php |  | ||||||
|  |  | ||||||
| namespace App\Console\Commands; |  | ||||||
|  |  | ||||||
| use App\Utils\CacheKey; |  | ||||||
| use Illuminate\Console\Command; |  | ||||||
| use App\Services\UserService; |  | ||||||
| use Illuminate\Support\Facades\Cache; |  | ||||||
|  |  | ||||||
| class CacheToken extends Command |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * The name and signature of the console command. |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     protected $signature = 'cache:token'; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * The console command description. |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     protected $description = '清理用户'; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Create a new command instance. |  | ||||||
|      * |  | ||||||
|      * @return void |  | ||||||
|      */ |  | ||||||
|     public function __construct() |  | ||||||
|     { |  | ||||||
|         parent::__construct(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Execute the console command. |  | ||||||
|      * |  | ||||||
|      * @return mixed |  | ||||||
|      */ |  | ||||||
|     public function handle() |  | ||||||
|     { |  | ||||||
|         $userService = new UserService(); |  | ||||||
|         $users = $userService->getAvailableUsers(); |  | ||||||
|         foreach ($users as $user) { |  | ||||||
|             Cache::put(CacheKey::get('SUBSCRIBE_TOKEN', $user->token), 1, 120); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -19,7 +19,7 @@ class Client | |||||||
|     public function handle($request, Closure $next) |     public function handle($request, Closure $next) | ||||||
|     { |     { | ||||||
|         $token = $request->input('token'); |         $token = $request->input('token'); | ||||||
|         if (empty($token) || $this->tokenNotInCache($token)) { |         if (empty($token)) { | ||||||
|             abort(403, 'token is null'); |             abort(403, 'token is null'); | ||||||
|         } |         } | ||||||
|         $user = User::where('token', $token)->first(); |         $user = User::where('token', $token)->first(); | ||||||
| @@ -29,12 +29,4 @@ class Client | |||||||
|         $request->user = $user; |         $request->user = $user; | ||||||
|         return $next($request); |         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; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -81,8 +81,6 @@ class OrderService | |||||||
|             abort(500, '开通失败'); |             abort(500, '开通失败'); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Cache::put(CacheKey::get('SUBSCRIBE_TOKEN', $this->user->token), 1, 120); |  | ||||||
|  |  | ||||||
|         DB::commit(); |         DB::commit(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,8 +19,7 @@ class CacheKey | |||||||
|         'TEMP_TOKEN' => '临时令牌', |         'TEMP_TOKEN' => '临时令牌', | ||||||
|         'LAST_SEND_EMAIL_REMIND_TRAFFIC' => '最后发送流量邮件提醒', |         'LAST_SEND_EMAIL_REMIND_TRAFFIC' => '最后发送流量邮件提醒', | ||||||
|         'SCHEDULE_LAST_CHECK_AT' => '计划任务最后检查时间', |         'SCHEDULE_LAST_CHECK_AT' => '计划任务最后检查时间', | ||||||
|         'REGISTER_IP_RATE_LIMIT' => '注册频率限制', |         'REGISTER_IP_RATE_LIMIT' => '注册频率限制' | ||||||
|         'SUBSCRIBE_TOKEN' => '订阅TOKEN' |  | ||||||
|     ]; |     ]; | ||||||
|  |  | ||||||
|     public static function get(string $key, $uniqueValue) |     public static function get(string $key, $uniqueValue) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user