index.php 1.61 KB
<?php

declare(strict_types=1);

require __DIR__ . '/../src/bootstrap.php';

if (!empty($_SESSION['login'])) {
    header('Location: dashboard.php');
    exit;
}

$erro = null;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $login = trim((string) ($_POST['login'] ?? ''));
    $senha = (string) ($_POST['senha'] ?? '');

    if ($login === '' || $senha === '') {
        $erro = 'Preencha login e senha.';
    } else {
        $result = Auth::attempt($login, $senha);
        if ($result['ok']) {
            header('Location: dashboard.php');
            exit;
        }
        $erro = $result['error'];
    }
} elseif (($_GET['erro'] ?? '') === 'sessao_expirada') {
    $erro = 'Sessão expirada. Faça login novamente.';
}
?>
<!doctype html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <title>Gestão de Alunos - LabInfo</title>
    <link rel="stylesheet" href="assets/style.css">
</head>
<body>
    <div class="login-wrap">
        <div class="card">
            <h1>Gestão de Alunos (AD)</h1>
            <?php if ($erro): ?>
                <div class="alert error"><?= htmlspecialchars($erro, ENT_QUOTES) ?></div>
            <?php endif; ?>
            <form method="post" action="index.php">
                <label for="login">Login</label>
                <input type="text" id="login" name="login" autocomplete="username" required autofocus>

                <label for="senha">Senha</label>
                <input type="password" id="senha" name="senha" autocomplete="current-password" required>

                <button type="submit">Entrar</button>
            </form>
        </div>
    </div>
</body>
</html>