Bienvenido, = htmlspecialchars($username) ?>
+Este es el panel de administración. Desde aquí podrás gestionar usuarios, ver reportes y configurar el sistema.
+diff --git a/add_patient.php b/add_patient.php index a20e19c..3ac642e 100644 --- a/add_patient.php +++ b/add_patient.php @@ -1,8 +1,16 @@ false, 'message' => 'Unauthorized']); + exit; +} + $response = ['success' => false, 'message' => 'An error occurred.']; if ($_SERVER['REQUEST_METHOD'] === 'POST') { diff --git a/auth.php b/auth.php new file mode 100644 index 0000000..1f2430d --- /dev/null +++ b/auth.php @@ -0,0 +1,54 @@ +prepare("SELECT * FROM users WHERE username = :username"); + $stmt->bindParam(':username', $username); + $stmt->execute(); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($user && password_verify($password, $user['password'])) { + // Regenerate session ID to prevent session fixation + session_regenerate_id(true); + + // Store user data in session + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; + $_SESSION['role'] = $user['role']; + + // Redirect based on role + if ($user['role'] === 'admin') { + header('Location: dashboard.php'); + } else { + // Redirect to a general user page or index if not admin + header('Location: index.php'); + } + exit; + } else { + $_SESSION['error'] = 'Usuario o contraseña incorrectos.'; + header('Location: login.php'); + exit; + } +} catch (PDOException $e) { + // In a real app, log this error instead of showing it to the user + $_SESSION['error'] = 'Error de base de datos. Intente de nuevo más tarde.'; + // error_log($e->getMessage()); + header('Location: login.php'); + exit; +} diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..929d9ce --- /dev/null +++ b/dashboard.php @@ -0,0 +1,43 @@ + + + +
+ + +Este es el panel de administración. Desde aquí podrás gestionar usuarios, ver reportes y configurar el sistema.
+