Refactor promoteur hub logic and enhance session handling

This commit updates the promoteur hub functionality by introducing a new function, `fxPromoteurHubIsAvailable`, to streamline the logic for determining hub access. The existing `fxPromoteurHubShouldUse` function is modified to incorporate this new check, improving clarity and maintainability. Additionally, comments are added to clarify session handling in the `fxLoginCompte` function, ensuring better understanding of public login behavior. These changes aim to enhance the robustness of the promoteur hub interface and improve code readability.
This commit is contained in:
2026-07-07 10:45:03 -04:00
parent 93cb9f5e81
commit 762ac838b6
4 changed files with 31 additions and 31 deletions

View File

@ -55,6 +55,7 @@ if (!empty($_GET['code']))
$strCode = 'compte_' . $_GET['code']; $strCode = 'compte_' . $_GET['code'];
else { else {
if (isset($_SESSION['com_id'])) { if (isset($_SESSION['com_id'])) {
// Legacy actif par défaut : accueil. Hub v2 seulement si promoteur_legacy_actif = 0 (voir fxPromoteurHubShouldUse).
if (fxPromoteurHubShouldUse($_SESSION['com_id'])) { if (fxPromoteurHubShouldUse($_SESSION['com_id'])) {
$strCode = 'compte_promoteur_hub'; $strCode = 'compte_promoteur_hub';
} else { } else {
@ -65,7 +66,7 @@ else {
} }
} }
if ($strCode === 'compte_promoteur_hub' && (!isset($_SESSION['com_id']) || !fxPromoteurHubShouldUse($_SESSION['com_id']))) { if ($strCode === 'compte_promoteur_hub' && (!isset($_SESSION['com_id']) || !fxPromoteurHubIsAvailable($_SESSION['com_id']))) {
header('Location: ' . $vDomaine . '/' . ($strLangue === 'fr' ? 'compte' : 'account')); header('Location: ' . $vDomaine . '/' . ($strLangue === 'fr' ? 'compte' : 'account'));
exit; exit;
} }

View File

@ -1198,7 +1198,8 @@ function fxLoginCompte($infoLogin, $strLangue)
fxcreer_log("ERREUR SQL UPDATE - fxLoginCompte()" . $sqlUpdate); fxcreer_log("ERREUR SQL UPDATE - fxLoginCompte()" . $sqlUpdate);
} }
//$_SESSION['logged'] = 1; // Login public : com_id + com_info seulement. Jamais usa_id ni canal superadm.
// com_info contient toute la ligne SQL (dont com_superadm) — ne pas s'en servir côté site public.
$_SESSION['com_id'] = $infoCompte['com_id']; $_SESSION['com_id'] = $infoCompte['com_id'];
$_SESSION['vadmin_texte'] = false; $_SESSION['vadmin_texte'] = false;
$_SESSION['com_info'] = $infoCompte; $_SESSION['com_info'] = $infoCompte;

View File

@ -43,12 +43,33 @@ function fxPromoteurHubPageExists()
return $blnExists; return $blnExists;
} }
/** Le compte doit-il atterrir sur le hub v2 ? (acces v2 + page installee) */ /** Hub v2 disponible (acces v2 + page CMS) — pour lien menu, pas pour forcer /compte. */
function fxPromoteurHubShouldUse($intComId) function fxPromoteurHubIsAvailable($intComId)
{ {
return fxPromoteurHubComUsesV2(intval($intComId)) && fxPromoteurHubPageExists(); return fxPromoteurHubComUsesV2(intval($intComId)) && fxPromoteurHubPageExists();
} }
/**
* Atterrissage par défaut sur le hub v2 (/compte, redirect après login public) ?
* Legacy site actif (promoteur_legacy_actif, défaut 1) : accueil + promoteur legacy, hub via lien seulement.
*/
function fxPromoteurHubShouldUse($intComId)
{
if (!fxPromoteurHubIsAvailable($intComId)) {
return false;
}
if (!function_exists('fxPromoteurLegacySiteEnabled')) {
require_once __DIR__ . '/inc_fonctions.php';
}
if (fxPromoteurLegacySiteEnabled()) {
return false;
}
return true;
}
function fxPromoteurHubUrl($strLangue = 'fr') function fxPromoteurHubUrl($strLangue = 'fr')
{ {
global $vDomaine; global $vDomaine;
@ -1235,7 +1256,7 @@ function fxShowPromoteurHubMenuLink($arrCompteClient, $strLangue)
{ {
global $vDomaine; global $vDomaine;
if (!fxPromoteurHubShouldUse(intval($arrCompteClient['com_id'] ?? 0))) { if (!fxPromoteurHubIsAvailable(intval($arrCompteClient['com_id'] ?? 0))) {
return ''; return '';
} }

View File

@ -1318,34 +1318,11 @@ function fxSuperadmSessionPingJson() {
} }
/** /**
* Dev préprod (preprod.ms1inscriptiondev) — superadm ouvert sans login, comme index.php avant MSIN-CON-259. * Super admin connecté — canal superadm/login.php uniquement (usa_id en session).
* Prod / client préprod : login superadm obligatoire. * Ne jamais déduire du login public : com_info / com_superadm ne comptent pas ici.
*/
function fxSuperadmDevPreprodOpenAccess() {
global $vblnEnvironementDev, $vblnEnvironementPreProd;
return !empty($vblnEnvironementDev) && !empty($vblnEnvironementPreProd);
}
/**
* Super admin connecté — usa_id (canal login.php) ou compte com_superadm en session.
* Ne pas exiger usa_info : rapport_new.php et vieux flux ne la posent pas toujours.
*/ */
function fxSuperadmIsLoggedIn() { function fxSuperadmIsLoggedIn() {
if (fxSuperadmDevPreprodOpenAccess()) { return !empty($_SESSION['usa_id']);
return true;
}
if (!empty($_SESSION['usa_id'])) {
return true;
}
if (!empty($_SESSION['usa_info']['com_superadm'])) {
return true;
}
if (!empty($_SESSION['com_info']['com_superadm'])) {
return true;
}
return fxSuperadmSessionValidate(false) > 0;
} }
/** /**