 21910f2106
			
		
	
	21910f2106
	
	
	
		
			
			Shift automatically applies the Laravel coding style - which uses the PSR-12 coding style as a base with some minor additions. You may customize the code style applied by configuring [Pint](https://laravel.com/docs/pint), [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer), or [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for your project root. For more information on customizing the code style applied by Shift, [watch this short video](https://laravelshift.com/videos/shift-code-style).
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Middleware;
 | |
| 
 | |
| use App\Model\helpdesk\Settings\System;
 | |
| use Closure;
 | |
| 
 | |
| class ApiKey
 | |
| {
 | |
|     public $setting;
 | |
| 
 | |
|     public function __construct()
 | |
|     {
 | |
|         $setting = new System();
 | |
|         $this->setting = $setting;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Handle an incoming request.
 | |
|      *
 | |
|      * @param  \Illuminate\Http\Request  $request
 | |
|      * @param  \Closure  $next
 | |
|      * @return mixed
 | |
|      */
 | |
|     public function handle($request, Closure $next)
 | |
|     {
 | |
|         $set = $this->setting->where('id', '1')->first();
 | |
|         if ($set->api_key_mandatory == 1) {
 | |
|             if ($set->api_enable == 1) {
 | |
|                 $key = $set->api_key;
 | |
|                 $check = $this->test($key, $request->input('api_key'));
 | |
|                 if ($check == '1') {
 | |
|                     return $next($request);
 | |
|                 }
 | |
|                 if ($check == '0') {
 | |
|                     $result = 'wrong api key';
 | |
| 
 | |
|                     return response()->json(compact('result'));
 | |
|                 }
 | |
|             } else {
 | |
|                 $result = 'please enable api';
 | |
| 
 | |
|                 return response()->json(compact('result'));
 | |
|             }
 | |
|         } else {
 | |
|             return $next($request);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public function test($v1, $v2)
 | |
|     {
 | |
|         if ($v1 == $v2) {
 | |
|             return '1';
 | |
|         } else {
 | |
|             return '0';
 | |
|         }
 | |
|     }
 | |
| }
 |