Login agents

[
‘username’ => ‘sam’,
‘name’ => ‘Sam – Service client’,
‘avatar’ => ‘S’,
‘password_hash’ => ‘$2y$12$vSGeeQYLVXTWbcuabwCabeeC26eepHwleiaYbaogitlpdiBLCrriK’
],
‘bruno’ => [
‘username’ => ‘bruno’,
‘name’ => ‘Bruno – Service client’,
‘avatar’ => ‘B’,
‘password_hash’ => ‘$2y$12$YcMcAxuTdfV5W4DgYaurX.8oGXtpPq3R0WpTZVooG3BTBFB1M71ZO’
]
];

$statusFile = __DIR__ . ‘/agents-status.json’;

$defaultStatus = [];
foreach ($AGENTS as $agentKey => $agentData) {
$defaultStatus[$agentKey] = false;
}

/* ============================
CRÉATION / LECTURE STATUS
============================ */

if (!file_exists($statusFile)) {
file_put_contents($statusFile, json_encode($defaultStatus, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}

$status = json_decode(file_get_contents($statusFile), true);

if (!is_array($status)) {
$status = $defaultStatus;
}

foreach ($defaultStatus as $agentKey => $value) {
if (!array_key_exists($agentKey, $status)) {
$status[$agentKey] = false;
}
}

/* ============================
API POUR LE WIDGET
============================ */

if (isset($_GET[‘api’]) && $_GET[‘api’] === ‘1’) {
header(‘Content-Type: application/json; charset=utf-8’);
header(‘Cache-Control: no-store, no-cache, must-revalidate, max-age=0’);
echo json_encode($status, JSON_UNESCAPED_UNICODE);
exit;
}

/* ============================
DÉCONNEXION
============================ */

if (isset($_GET[‘logout’])) {
session_destroy();
header(‘Location: agent-status.php’);
exit;
}

/* ============================
CONNEXION
============================ */

$error =  »;

if ($_SERVER[‘REQUEST_METHOD’] === ‘POST’ && isset($_POST[‘login’])) {
$username = strtolower(trim($_POST[‘username’] ??  »));
$password = $_POST[‘password’] ??  »;

$foundAgentKey = null;

foreach ($AGENTS as $agentKey => $agentData) {
if (strtolower($agentData[‘username’]) === $username) {
$foundAgentKey = $agentKey;
break;
}
}

if ($foundAgentKey !== null && password_verify($password, $AGENTS[$foundAgentKey][‘password_hash’])) {
session_regenerate_id(true);
$_SESSION[‘agent_key’] = $foundAgentKey;
header(‘Location: agent-status.php’);
exit;
} else {
$error = ‘Nom d’utilisateur ou mot de passe incorrect.’;
}
}

/* ============================
CHANGEMENT DE STATUT
Chaque agent change seulement son propre statut.
============================ */

if (isset($_SESSION[‘agent_key’]) && isset($_POST[‘set_status’])) {
$agentKey = $_SESSION[‘agent_key’];

if (array_key_exists($agentKey, $AGENTS)) {
$newStatus = $_POST[‘set_status’] === ‘1’;
$status[$agentKey] = $newStatus;

file_put_contents($statusFile, json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));

header(‘Location: agent-status.php’);
exit;
}
}

$isLoggedIn = isset($_SESSION[‘agent_key’]) && array_key_exists($_SESSION[‘agent_key’], $AGENTS);
$currentAgentKey = $isLoggedIn ? $_SESSION[‘agent_key’] : null;
$currentAgent = $isLoggedIn ? $AGENTS[$currentAgentKey] : null;
$currentStatus = $isLoggedIn ? (bool)$status[$currentAgentKey] : false;

?>





Connexion agents EvolutaTV


Agents EvolutaTV

Connexion sécurisée




Chaque agent peut seulement modifier son propre statut.

● Présentement en ligne

● Présentement hors ligne






Déconnexion

Le widget du site se mettra à jour automatiquement.


Scroll to Top
Support Evolutatv Choisissez un agent disponible
S
Sam - Service client Chargement...
B
Bruno - Service client Chargement...