Update v1.0.6
This commit is contained in:
40
app/Http/Middleware/ApiKey.php
Normal file
40
app/Http/Middleware/ApiKey.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Model\helpdesk\Settings\System;
|
||||
|
||||
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_enable == 1) {
|
||||
$key = $set->api_key;
|
||||
if ($key == $request->input('api-key')) {
|
||||
return $next($request);
|
||||
} else {
|
||||
$result = 'wrong api key';
|
||||
return response()->json(compact('result'));
|
||||
}
|
||||
} else {
|
||||
$result = 'please enable api';
|
||||
return response()->json(compact('result'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user