26 lines
784 B
PHP
26 lines
784 B
PHP
<?php
|
|
// api/log_auth.php - Logs Authentication Events (Login)
|
|
|
|
header("Content-Type: application/json; charset=UTF-8");
|
|
require_once '../config/db.php';
|
|
require_once 'logger.php';
|
|
|
|
try {
|
|
$input = file_get_contents('php://input');
|
|
$data = json_decode($input, true);
|
|
|
|
if (!$data || !isset($data['user_id']) || !isset($data['user_name']) || !isset($data['action'])) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Invalid data']);
|
|
exit;
|
|
}
|
|
|
|
$db = getDbConnection();
|
|
$pdo = $db['pdo'];
|
|
|
|
logActivity($pdo, $data['user_id'], $data['user_name'], $data['action'], $data['details'] ?? '');
|
|
|
|
echo json_encode(['status' => 'success']);
|
|
} catch (\Exception $e) {
|
|
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
|
}
|