108 lines
4.4 KiB
PHP
108 lines
4.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/config.php';
|
|
require_once __DIR__ . '/includes/db.php';
|
|
require_once __DIR__ . '/includes/auth.php';
|
|
require_once __DIR__ . '/includes/theme.php';
|
|
|
|
if (ao_usuario_logado()) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
$erro = null;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$email = trim($_POST['email'] ?? '');
|
|
$senha = (string) ($_POST['senha'] ?? '');
|
|
|
|
$stmt = $pdo->prepare('SELECT * FROM usuarios WHERE email = ? AND ativo = 1');
|
|
$stmt->execute([$email]);
|
|
$usuarioDb = $stmt->fetch();
|
|
|
|
if ($usuarioDb && password_verify($senha, $usuarioDb['senha_hash'])) {
|
|
$stmtPerfil = $pdo->prepare('SELECT * FROM perfis WHERE id = ? AND ativo = 1');
|
|
$stmtPerfil->execute([$usuarioDb['perfil_id']]);
|
|
$perfilDb = $stmtPerfil->fetch();
|
|
|
|
if (!$perfilDb) {
|
|
$erro = 'Seu perfil de acesso está inativo. Fale com um administrador.';
|
|
} else {
|
|
ao_carregar_sessao_usuario($pdo, $usuarioDb, $perfilDb);
|
|
session_regenerate_id(true);
|
|
|
|
$pdo->prepare('UPDATE usuarios SET ultimo_login = NOW() WHERE id = ?')->execute([$usuarioDb['id']]);
|
|
|
|
$destino = $_SESSION['ao_pos_login'] ?? 'index.php';
|
|
unset($_SESSION['ao_pos_login']);
|
|
header('Location: ' . $destino);
|
|
exit;
|
|
}
|
|
} else {
|
|
$erro = 'E-mail ou senha inválidos.';
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="pt-BR" data-ao-mode="<?= htmlspecialchars($ao_modo) ?>">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Entrar — AçãoOpção</title>
|
|
<link rel="icon" href="<?= htmlspecialchars($ao_tema_atual['favicon']) ?>">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@500;600;700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="<?= htmlspecialchars($ao_tema_atual['css']) ?>">
|
|
<style>
|
|
* { box-sizing: border-box; }
|
|
body {
|
|
margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center;
|
|
background: var(--ao-bg-page); color: var(--ao-text-body);
|
|
}
|
|
.ao-login-card {
|
|
width: 100%; max-width: 380px; margin: 24px; padding: var(--ao-space-6);
|
|
background: var(--ao-bg-surface); border: 1px solid var(--ao-border);
|
|
border-radius: var(--ao-radius-lg, 16px); box-shadow: var(--ao-shadow-md);
|
|
}
|
|
.ao-login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: var(--ao-space-5); }
|
|
.ao-login-brand img { width: 32px; height: 32px; border-radius: 9px; }
|
|
.ao-login-brand strong { font-family: 'Poppins', sans-serif; font-size: 1.1rem; color: var(--ao-text-strong); }
|
|
.ao-login-card h1 { font-size: 1.15rem; margin: 0 0 var(--ao-space-4); color: var(--ao-text-strong); }
|
|
.ao-field { margin-bottom: var(--ao-space-4); }
|
|
.ao-field label { display: block; font-size: var(--ao-fs-xs); font-weight: 600; margin-bottom: 6px; color: var(--ao-text-muted); }
|
|
.ao-erro {
|
|
background: var(--ao-baixa-bg, #fdf1ef); color: var(--ao-baixa-text, #a4372b);
|
|
padding: 10px 14px; border-radius: 8px; font-size: var(--ao-fs-sm); margin-bottom: var(--ao-space-4);
|
|
}
|
|
.ao-login-rodape { margin-top: var(--ao-space-5); font-size: var(--ao-fs-xs); color: var(--ao-text-muted); text-align: center; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="ao-login-card">
|
|
<div class="ao-login-brand">
|
|
<img src="<?= htmlspecialchars($ao_tema_atual['icone']) ?>" alt="">
|
|
<strong>AçãoOpção</strong>
|
|
</div>
|
|
<h1>Entrar na sua conta</h1>
|
|
|
|
<?php if ($erro): ?>
|
|
<div class="ao-erro"><?= htmlspecialchars($erro) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" action="login.php">
|
|
<div class="ao-field">
|
|
<label for="email">E-mail</label>
|
|
<input type="email" id="email" name="email" required autofocus value="<?= htmlspecialchars($_POST['email'] ?? '') ?>">
|
|
</div>
|
|
<div class="ao-field">
|
|
<label for="senha">Senha</label>
|
|
<input type="password" id="senha" name="senha" required>
|
|
</div>
|
|
<button type="submit" class="ao-btn ao-btn-primary" style="width:100%;">Entrar</button>
|
|
</form>
|
|
|
|
<p class="ao-login-rodape">AçãoOpção — acesso restrito a usuários cadastrados.</p>
|
|
</div>
|
|
</body>
|
|
</html>
|