'; echo '' . $title . ''; echo '
'; // Icône echo '
'; if ($type === 'success') { echo '
'; } elseif ($type === 'info') { echo '
'; } else { // error echo '
'; } echo '
'; echo '

' . $title . '

'; echo '

' . $message . '

'; if ($cta_href) { echo '
' . $cta_label . '
'; } echo '
'; exit; } // ===================== // 1) Token présent & valide // ===================== $rawToken = trim((string) ($_GET['token'] ?? '')); if ($rawToken === '') { ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['err_lien_invalide'] ?? 'Lien invalide.', 400, 'error', '/', $translations['retour_acceuil'] ?? 'Retour à l’accueil' ); } // Optionnel : on vérifie le format attendu (bin2hex(32) => 64 hexdigits) if (! preg_match('/^[A-Fa-f0-9]{64}$/', $rawToken)) { ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['err_lien_invalide'] ?? 'Lien invalide.', 400, 'error', '/', $translations['retour_acceuil'] ?? 'Retour à l’accueil' ); } // ===================== // 2) Récupération du compte // ===================== $stmt = $pdo->prepare("SELECT * FROM compte WHERE token_validation = :token LIMIT 1"); $stmt->execute(['token' => $rawToken]); $compte = $stmt->fetch(); if (! $compte) { ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['err_token_invalide'] ?? 'Token invalide.', 400, 'error', '/', $translations['retour_acceuil'] ?? 'Retour à l’accueil' ); } // ===================== // 3) Validité temporelle (6h) // ===================== try { if (empty($compte['token_validation_expire'])) { throw new RuntimeException('token_validation_expire manquant'); } $expireAt = new DateTime((string) $compte['token_validation_expire']); } catch (Throwable $e) { ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['tvalidat_err_lien_invalide'] ?? $translations['err_lien_invalide'] ?? 'Lien invalide.', 400, 'error', '/', $translations['retour_acceuil'] ?? 'Retour à l’accueil' ); } $now = new DateTime(); if ($now > $expireAt) { ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['tvalidat_err_lien_expire'] ?? $translations['err_lien_expire'] ?? 'Le lien de validation a expiré.', 410, 'info', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' ); } // ===================== // 4) Valider l'email (maj compte) // ===================== try { $stmt = $pdo->prepare(" UPDATE compte SET email_valide = 1, token_validation = NULL, token_validation_expire = NULL, token_autologin = NULL, token_autologin_expire = NULL WHERE id = :id "); $stmt->execute(['id' => $compte['id']]); } catch (Throwable $e) { error_log('Validation email - UPDATE échouée: ' . $e->getMessage()); ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['err_serveur'] ?? 'Erreur serveur.', 500, 'error', '/', $translations['retour_acceuil'] ?? 'Retour à l’accueil' ); } // ===================== // 4bis) Auto-login direct après validation // ===================== session_regenerate_id(true); $_SESSION['compte_id'] = (int) $compte['id']; $_SESSION['role'] = (string) $compte['role']; $_SESSION['reference_id'] = (int) $compte['reference_id']; if ($_SESSION['role'] === 'client') { $_SESSION['client_id'] = (int) $compte['reference_id']; header('Location: /public/client/informations.php'); exit; } if ($_SESSION['role'] === 'praticien') { $_SESSION['praticien_id'] = (int) $compte['reference_id']; header('Location: /public/praticien/informations.php'); exit; } header('Location: /connexion.php'); exit; // ===================== // 5) Écran final (succès) // ===================== // Le texte de succès chez toi contient un lien HTML ; on affiche un message “texte” + un vrai bouton vers la connexion. $successMsg = isset($translations['success_validation_texte']) ? strip_tags((string) $translations['success_validation_texte']) : 'Votre compte est confirmé. Vous pouvez maintenant vous connecter.'; ui_exit( $translations['success_validation_titre'] ?? 'Compte confirmé !', $successMsg, 200, 'success', '/connexion.php', $translations['btn_se_connecter'] ?? 'Se connecter' );