/**
  * @Before("execution(public Autenticacao\Controllers\ListaUsuarioController->*(*))")
  * 
  * @param MethodInvocation $invocation            
  */
 public function beforeMethodExecution(MethodInvocation $invocation)
 {
     $container = Container::obtemInstancia();
     $mapper = $container->mapper;
     $headers = apache_request_headers();
     $token = null;
     $bearer = null;
     $resposta = new stdClass();
     $resposta->success = false;
     if (!isset($headers['Authorization'])) {
         die(json_encode($resposta));
     }
     $authorization = (string) $headers['Authorization'];
     $acessoToken = new AcessoToken($mapper);
     if ($acessoToken->validaFormatoDoToken($authorization)) {
         list($bearer, $token) = explode(" ", $authorization);
     }
     $acessoTokenRepository = new AcessoTokenRepository($mapper);
     $sessaoValida = $acessoTokenRepository->obtemPorTokenValido($token);
     if (!$sessaoValida) {
         die(json_encode($resposta));
     }
 }
 public function post()
 {
     parse_str(file_get_contents('php://input'), $_REQUEST);
     $login = !empty($_REQUEST['login']) ? $_REQUEST['login'] : null;
     $senha = !empty($_REQUEST['senha']) ? $_REQUEST['senha'] : null;
     $resposta = new stdClass();
     $resposta->success = false;
     $usuarioRepository = new UsuarioRepository($this->mapper);
     $usuario = $usuarioRepository->obtemPorLogin($login);
     $autentica = $usuario->autentica($senha);
     if ($autentica) {
         $acessoToken = new AcessoToken();
         $acessoToken->defineUsuario($usuario);
         $acessoToken->defineDataHoraInicio(date("Y-m-d H:i:s"));
         $acessoToken->defineDataHoraFim($acessoToken->calculaDataHoraFim());
         $acessoToken->defineTokenAcesso($acessoToken->geraTokenAcesso());
         $this->mapper->acessoToken->persist($acessoToken);
         $this->mapper->flush();
         $resposta->success = true;
         $resposta->acessoToken = $acessoToken->obtemCopia();
     }
     return $resposta;
 }