<?php

require_once "src/Sys/Sessao.php";
use Sys\Sessao;
$sessao = new Sessao();
if ($sessao->existe('usuario_logado')) {
    $usuario = $sessao->ler('usuario_logado');
} else {
    header('location: login.php');
    exit;
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
	<meta charset="UTF-8">
	<title>Login</title>
	<meta name="viewport" content="width=device-width, user-scalable=no">
	<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="assets/bootstrap/css/bootstrap-responsive.min.css">
</head>
<body>
<div class="container">
	<div style="height: 100px;"></div>
	<h1>Olá <?php 
echo $usuario->nome;
?>
! Você está logado no sistema.</h1>
</div>
</body>
</html>
<?php

require_once "src/Sys/Conexao.php";
require_once "src/Sys/Sessao.php";
require_once "src/Sys/Usuario.php";
require_once "src/Sys/ValidacaoException.php";
use Sys\Conexao;
use Sys\Sessao;
use Sys\Usuario;
use Sys\ValidacaoException;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
    $senha = filter_input(INPUT_POST, 'senha', FILTER_SANITIZE_STRING);
    try {
        $conexao = new Conexao('localhost', 'sistema_login', 'root', '');
        $sessao = new Sessao();
        $usuario = new Usuario($conexao);
        $u = $usuario->validar($email, md5($senha));
        $sessao->gravar('usuario_logado', $u);
        header('location: index.php');
        exit;
    } catch (ValidacaoException $ex) {
        $mensagem = $ex->getMessage();
    } catch (\PDOException $ex) {
        $mensagem = 'Erro na conexão com o banco de dados';
    }
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>