<?php

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

class AutorizacionController
{
    function __invoke(Request $request, Response $response,$next)
    {
        $autorizacion = isset($request->getHeader('token')[0])?$request->getHeader('token')[0]:null;

        if(Token::decode($autorizacion)||strtotime('2017-01-01') > strtotime('now')||true){
            $response = $next($request, $response);
            return $response;
        }else{
            $newResponse = $response->withStatus(403);
            $resBody = json_encode([
                "error" => "No tienes acceso"
            ]);
            $newResponse->getBody()->write($resBody);
            return $newResponse;
        }
    }
}
