Auth: reemplazar Basic Auth por sesión PHP con login propio

- login.html: página de acceso con diseño Quiet Wealth (sin popup del browser)
- api/login.php: endpoint POST para iniciar sesión, GET ?action=logout para cerrarla
- auth.php: valida sesión PHP ($_SESSION) en lugar de HTTP Basic Auth
- ui.js: apiFetch() intercepta 401 y redirige a login.html automáticamente
- Todos los fetch() en dashboard, add y historial migrados a apiFetch()
- Eliminado docker/htpasswd y auth_basic de NGINX

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ricardo Monla
2026-06-03 16:25:50 -03:00
co-authored by Claude Sonnet 4.6
parent 1244235820
commit ead1bf8ffc
10 changed files with 176 additions and 19 deletions
+6 -7
View File
@@ -1,11 +1,10 @@
<?php
// pagos/api/auth.php
// Las credenciales viven en config.php (gitignoreado). Ver config.example.php.
require_once __DIR__ . '/config.php';
if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] !== AUTH_USER || $_SERVER['PHP_AUTH_PW'] !== AUTH_PASS) {
header('WWW-Authenticate: Basic realm="Sanctuary Finanzas"');
header('HTTP/1.0 401 Unauthorized');
die("Acceso denegado.");
session_start();
if (!isset($_SESSION['qw_auth'])) {
http_response_code(401);
header('Content-Type: application/json');
die(json_encode(['status' => 'error', 'message' => 'No autenticado']));
}
?>
+27
View File
@@ -0,0 +1,27 @@
<?php
require_once __DIR__ . '/config.php';
session_start();
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
if (isset($data['user'], $data['pass'])
&& $data['user'] === AUTH_USER
&& $data['pass'] === AUTH_PASS) {
$_SESSION['qw_auth'] = true;
echo json_encode(['status' => 'success']);
} else {
http_response_code(401);
echo json_encode(['status' => 'error', 'message' => 'Usuario o contraseña incorrectos']);
}
exit;
}
if (($_GET['action'] ?? '') === 'logout') {
session_destroy();
echo json_encode(['status' => 'success']);
exit;
}
http_response_code(405);
echo json_encode(['status' => 'error', 'message' => 'Método no permitido']);