<?php

namespace App\Http\Middleware;

use Closure;

class isAuthorized
{

	/**
	 * Handle an incoming request.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @param  \Closure  $next
	 * @return mixed
	 */



	public function handle($request, Closure $next)
	{

		function getheaders()
		{
			$headers = [];
			foreach ($_SERVER as $name => $value) {
				if (substr($name, 0, 5) == 'HTTP_') {
					$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
				}
			}
			return $headers;
		}

		if (isset(getheaders()['Token']) && getheaders()['Token'] == "1HHIaIsT4pvO2S39vMzlVfGWi3AhAz6F5xGBNKil") {
			return $next($request);
		} else {
			return response()->json(['status' => false, 'error' => "Invalid request"], 503);
		}
	}
}
