'; 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; } // ===================== // Accès direct interdit // ===================== if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') { ui_exit( $translations['err_acces_incorrect_titre'] ?? 'Accès incorrect', $translations['err_acces_incorrect_msg'] ?? "Cette page doit être appelée depuis le formulaire d'inscription.", 405, 'info', 'inscription_client.php', $translations['retour_formulaire'] ?? 'Retour au formulaire' ); } // ===================== // Données & vérifs // ===================== $nom = trim($_POST['nom'] ?? ''); $prenom = trim($_POST['prenom'] ?? ''); $email = trim($_POST['email'] ?? ''); $mdp = $_POST['mot_de_passe'] ?? ''; // Champs obligatoires if ($nom === '' || $prenom === '' || $email === '' || $mdp === '') { ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['err_champs_obligatoires'] ?? 'Merci de remplir tous les champs obligatoires.', 400, 'error', 'inscription_client.php', $translations['retour_formulaire'] ?? 'Retour au formulaire' ); } // Email valide + pas d’injection CR/LF if (! filter_var($email, FILTER_VALIDATE_EMAIL) || preg_match('/[\r\n]/', $email)) { ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['err_email_non_valide'] ?? 'Email invalide.', 400, 'error', 'inscription_client.php' ); } // Acceptation CGU $accept_cgu = isset($_POST['accept_cgu']) ? 1 : 0; if ($accept_cgu !== 1) { ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['cgu_obligatoire'] ?? 'Vous devez accepter les CGU.', 400, 'info', 'inscription_client.php' ); } // ===================== // Transaction (client + compte) // ===================== try { $pdo->beginTransaction(); // Email déjà pris ? $stmt = $pdo->prepare("SELECT id FROM compte WHERE email = :email LIMIT 1"); $stmt->execute(['email' => $email]); if ($stmt->fetch()) { $pdo->rollBack(); ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['err_email_deja_utilise'] ?? 'Cet email est déjà utilisé.', 409, 'error', 'inscription_client.php' ); } // 1) Insert client $stmt = $pdo->prepare("INSERT INTO client (nom, prenom, email, accepted_cgu) VALUES (:nom, :prenom, :email, :accepted_cgu)"); $stmt->execute([ 'nom' => $nom, 'prenom' => $prenom, 'email' => $email, 'accepted_cgu' => $accept_cgu, ]); $client_id = (int) $pdo->lastInsertId(); // 2) Créer compte $mot_de_passe_hash = password_hash($mdp, PASSWORD_DEFAULT); $token = bin2hex(random_bytes(32)); $token_validation_expire = (new DateTime('+6 hours'))->format('Y-m-d H:i:s'); $token_autologin = bin2hex(random_bytes(32)); $token_autologin_expire = (new DateTime('+60 minutes'))->format('Y-m-d H:i:s'); $stmt = $pdo->prepare(" INSERT INTO compte ( email, mot_de_passe, role, reference_id, token_validation, token_validation_expire, email_valide, token_autologin, token_autologin_expire ) VALUES ( :email, :mdp, 'client', :ref_id, :token, :token_expire, 0, :al, :al_exp ) "); $stmt->execute([ 'email' => $email, 'mdp' => $mot_de_passe_hash, 'ref_id' => $client_id, 'token' => $token, 'token_expire' => $token_validation_expire, 'al' => $token_autologin, 'al_exp' => $token_autologin_expire, ]); // Commit avant l’envoi du mail $pdo->commit(); } catch (Throwable $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } error_log('Inscription client - DB error: ' . $e->getMessage()); ui_exit( $translations['err_titre'] ?? 'Un problème est survenu', $translations['err_serveur'] ?? 'Erreur serveur.', 500, 'error', '/' ); } // ===================== // Email de validation // ===================== $validation_url = "https://uslugi.fr/validation.php?token=" . urlencode($token) . "&al=" . urlencode($token_autologin); $validation_url_html = htmlspecialchars($validation_url, ENT_QUOTES, 'UTF-8'); $prenom_nom_safe = htmlspecialchars("$prenom $nom", ENT_QUOTES, 'UTF-8'); $sujet = $translations['mail_valid_sujet']; $html = "
" . sprintf($translations['mail_valid_bonjour_nom'], $prenom_nom_safe) . "

" . $translations['mail_valid_merci'] . "

" . $translations['mail_valid_action'] . "

" . $translations['mail_valid_btn'] . "
"; $text = strip_tags( sprintf($translations['mail_valid_bonjour_nom'], "$prenom $nom") . "\n\n" . $translations['mail_valid_merci'] . "\n" . $translations['mail_valid_action'] . "\n" . ($translations['mail_valid_fallback'] ?? 'Si le bouton ne fonctionne pas, utilisez ce lien :') . "\n" . $validation_url . "\n\n" . $translations['mail_valid_expire'] . "\n" . $translations['mail_valid_ignore'] . "\n" . ($translations['mail_valid_signature'] ?? 'USLUGI.FR') ); // Envoi du mail (non bloquant) list($sent, $err) = uslugi_mail( $email, $sujet, $html, $text, ['to_name' => "$prenom $nom"] ); if (! $sent) { error_log("Validation mail NOT sent to $email : $err"); // On ne bloque pas l'utilisateur. } // ===================== // Écran final (succès) // ===================== echo ' ' . htmlspecialchars($translations['insc_merci_titre'] ?? 'Merci !', ENT_QUOTES, 'UTF-8') . '

' . htmlspecialchars($translations['insc_merci_titre'] ?? 'Merci !', ENT_QUOTES, 'UTF-8') . '

' . htmlspecialchars($translations['insc_merci_ligne1'] ?? 'Votre compte a bien été créé.', ENT_QUOTES, 'UTF-8') . '

' . htmlspecialchars($translations['insc_merci_ligne2'] ?? 'Vérifiez vos emails pour valider votre adresse.', ENT_QUOTES, 'UTF-8') . '

' . htmlspecialchars($translations['retour_acceuil'] ?? 'Retour à l’accueil', ENT_QUOTES, 'UTF-8') . '
';