mirror of
				https://github.com/v2board/v2board.git
				synced 2025-11-01 01:41:47 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			767 B
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			767 B
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Middleware;
 | |
| 
 | |
| use App\Services\AuthService;
 | |
| use Closure;
 | |
| use Illuminate\Support\Facades\Cache;
 | |
| 
 | |
| class Admin
 | |
| {
 | |
|     /**
 | |
|      * Handle an incoming request.
 | |
|      *
 | |
|      * @param \Illuminate\Http\Request $request
 | |
|      * @param \Closure $next
 | |
|      * @return mixed
 | |
|      */
 | |
|     public function handle($request, Closure $next)
 | |
|     {
 | |
|         $authorization = $request->input('auth_data') ?? $request->header('authorization');
 | |
|         if (!$authorization) abort(403, '未登录或登陆已过期');
 | |
| 
 | |
|         $user = AuthService::decryptAuthData($authorization);
 | |
|         if (!$user || !$user['is_admin']) abort(403, '未登录或登陆已过期');
 | |
|         $request->merge([
 | |
|             'user' => $user
 | |
|         ]);
 | |
|         return $next($request);
 | |
|     }
 | |
| }
 |