Files
trimape_web/blog/admin/login.php
T
2026-07-15 19:45:08 -06:00

114 lines
3.6 KiB
PHP

<?php
require_once __DIR__ . '/auth.php';
// If already logged in, redirect to dashboard
if (isLoggedIn()) {
header('Location: ' . BLOG_URL . '/admin/');
exit;
}
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
if ($username === '' || $password === '') {
$error = 'Ingresa usuario y contraseña.';
} else {
$db = getDB();
$stmt = $db->prepare("SELECT id, username, password_hash FROM blog_admins WHERE username = :u LIMIT 1");
$stmt->execute([':u' => $username]);
$admin = $stmt->fetch();
if ($admin && password_verify($password, $admin['password_hash'])) {
session_regenerate_id(true);
$_SESSION['blog_admin_id'] = $admin['id'];
header('Location: ' . BLOG_URL . '/admin/');
exit;
} else {
$error = 'Usuario o contraseña incorrectos.';
}
}
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100..900&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Admin Login - Blog TRIMAPE</title>
<style>
* { font-family: 'Montserrat', sans-serif; }
body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #0a1d3b 0%, #0e55bb 50%, #1186cc 100%);
}
.login-card {
background: white;
border-radius: 16px;
padding: 3rem;
width: 100%;
max-width: 420px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-card .logo { height: 50px; margin-bottom: 1.5rem; }
.login-card h4 { color: #0a1d3b; font-weight: 700; }
.form-control {
border-radius: 10px;
padding: 12px 16px;
border: 2px solid #e8eef5;
transition: border-color 0.2s;
}
.form-control:focus {
border-color: #0e55bb;
box-shadow: 0 0 0 3px rgba(14,85,187,0.15);
}
.btn-login {
background: linear-gradient(135deg, #0e55bb, #1186cc);
border: none;
color: white;
font-weight: 700;
padding: 12px;
border-radius: 10px;
width: 100%;
transition: all 0.2s;
}
.btn-login:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(14,85,187,0.35);
color: white;
}
</style>
</head>
<body>
<div class="login-card text-center">
<img src="<?= SITE_URL ?>/assets/img/trimape-logo-512-300x300.png" alt="TRIMAPE" class="logo">
<h4 class="mb-1">Blog Admin</h4>
<p class="text-muted mb-4" style="font-size: 0.85rem;">Inicia sesión para administrar el blog</p>
<?php if ($error): ?>
<div class="alert alert-danger py-2" style="font-size: 0.85rem; border-radius: 10px;"><?= e($error) ?></div>
<?php endif; ?>
<form method="POST" autocomplete="off">
<div class="mb-3">
<input type="text" name="username" class="form-control" placeholder="Usuario" required autofocus
value="<?= e($username ?? '') ?>">
</div>
<div class="mb-4">
<input type="password" name="password" class="form-control" placeholder="Contraseña" required>
</div>
<button type="submit" class="btn btn-login">Iniciar sesión</button>
</form>
<a href="<?= BLOG_URL ?>" class="d-block mt-3 text-muted" style="font-size: 0.8rem;">← Volver al blog</a>
</div>
</body>
</html>