index.php
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?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>