public function sendHeader()
 {
     header($this->message, true, $this->code);
     if ($previous = $this->getPrevious()) {
         exception_header($previous, $this->code);
     }
 }
Exemplo n.º 2
0
 public function doPost()
 {
     $r = UsuarioResource::getInstance();
     $usuario = Usuario::fromArray($r->getRequest());
     if ($usuario->getEmail()) {
         if ($usuario->getSenha()) {
             if ($usuario->getUsername()) {
                 $m = UsuarioController::cadastrar($usuario);
                 if ($m) {
                     created_header();
                     echo $usuario->getJson("nome,username,email,codigo");
                 } else {
                     exception_header();
                     UsuarioController::print_exception("cadastrar");
                 }
             } else {
                 bad_request_header();
             }
         } else {
             UsuarioController::porEmail($usuario->getEmail());
             ok_header();
             if (UsuarioController::get("id")) {
                 echo UsuarioController::$usuario->getJson("id,nome,username,email,codigo,status,departamento");
             } else {
                 echo $usuario->getJson("email");
             }
         }
     } else {
         bad_request_header();
     }
 }
Exemplo n.º 3
0
 public function doGet()
 {
     $r = UsuarioResource::getInstance();
     if (isset($_COOKIE["credentials"])) {
         SessaoController::autenticar($_COOKIE["credentials"]);
         if (UsuarioController::get("id")) {
             ok_header();
             echo UsuarioController::$usuario->json();
         } else {
             exception_header();
             SessaoController::print_exception("autenticar");
         }
     } else {
         bad_request();
     }
 }
Exemplo n.º 4
0
 public function doPost()
 {
     $r = DepartamentoResource::getInstance();
     if ($r->getRequest("nome") and $r->getRequest("email")) {
         $ve = DepartamentoController::validateEmail($r->getRequest("email"));
         if ($ve) {
             $departamento = Departamento::fromArray($r->getRequest(), "nome,email,endereco,telefone");
             $x = DepartamentoController::novo($departamento);
             if ($x) {
                 created_header();
             } else {
                 exception_header();
                 DepartamentoController::print_exception("novo");
             }
         } else {
             exception_header();
             DepartamentoController::print_exception("email");
         }
     } else {
         exception_header();
         echo "'Nome do Departamento' e 'E-mail' são campos obrigatórios.";
     }
 }
Exemplo n.º 5
0
}
?>

<?php 
if (isset($_COOKIE["credentials"])) {
    SessaoController::autenticar($_COOKIE["credentials"]);
    if (UsuarioController::get("id")) {
        if (isset($_POST["codigo"])) {
            $o = UsuarioController::ativarConta($_POST["codigo"]);
            if ($o) {
                ok_header();
            } else {
                exception_header();
                UsuarioController::print_exception("ativar_conta");
            }
        } else {
            $o = UsuarioController::solicitarAtivacaoDeConta();
            if ($o) {
                ok_header();
            } else {
                exception_header();
                echo "Houve um erro!";
            }
        }
    } else {
        exception_header();
        SessaoController::prin_exception("autenticar");
    }
} else {
    bad_request_header();
}
 /**
  * @param \Exception $e_
  */
 public static function addException(\Exception $e_)
 {
     exception_header($e_);
     exception_log($e_);
     array_push(self::$m_exceptions, $e_);
 }
/**
 * Send header containing details for given exception.
 *
 * @param \Exception $e_
 * @param integer $code_
 */
function exception_header(\Exception $e_, $code_ = 500)
{
    if ($cause = $e_->getPrevious()) {
        exception_header($cause, $code_);
    }
    $firstException = false === isset($GLOBALS['components_runtime_exception_header']);
    if ($firstException) {
        $GLOBALS['components_runtime_exception_header'] = 1;
    } else {
        $GLOBALS['components_runtime_exception_header']++;
    }
    header("Components-Exception-Count: {$GLOBALS['components_runtime_exception_header']}");
    if ($GLOBALS['components_runtime_exception_header'] > 10) {
        return;
    }
    if (false === headers_sent()) {
        $hash = \math\hasho_md5($e_);
        if (\Components\Runtime::isManagementAccess()) {
            if ($firstException) {
                header("Components-Exception-{$hash}: " . json_encode([$hash, $e_->getFile(), $e_->getLine(), exception_as_array($e_, true, false)]), true, $code_);
            } else {
                header("Components-Exception-{$hash}: " . json_encode([$hash, $e_->getFile(), $e_->getLine(), exception_as_array($e_, true, false)]));
            }
        } else {
            if ($firstException) {
                header("Components-Exception-{$hash}: {$hash}", true, $code_);
            } else {
                header("Components-Exception-{$hash}: {$hash}");
            }
        }
    }
}