Connexion tocken, stripe 3D, tracking analytic
This commit is contained in:
1 parent
1deb30fcd1
commit
bd311da711
17 files changed
+3324
-455
No files matched your search
@@ -1,36 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
declare (strict_types = 1);
|
||||
require_once __DIR__ . '/../includes/bootstrap_global.php';
|
||||
|
||||
/**
|
||||
* UI helper: affiche une jolie carte centrée puis exit.
|
||||
* $type: 'error' | 'info' | 'success'
|
||||
*/
|
||||
function ui_exit(string $title, string $message, int $status = 400, string $type = 'error', ?string $cta_href = '/', ?string $cta_label = null): void {
|
||||
function ui_exit(string $title, string $message, int $status = 400, string $type = 'error', ?string $cta_href = '/', ?string $cta_label = null): void
|
||||
{
|
||||
http_response_code($status);
|
||||
$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
|
||||
$message = nl2br(htmlspecialchars($message, ENT_QUOTES, 'UTF-8'));
|
||||
$cta_href = $cta_href ? htmlspecialchars($cta_href, ENT_QUOTES, 'UTF-8') : null;
|
||||
$cta_label = $cta_label ?? 'OK';
|
||||
|
||||
// Styles d'icône selon le type
|
||||
// Styles d'icône selon le type
|
||||
$iconBorder = '#B91C1C'; // rouge par défaut (error)
|
||||
$iconBg = 'rgba(185,28,28,.08)';
|
||||
$iconRing = 'rgba(185,28,28,.25)';
|
||||
$checkCSS = ''; // pour success
|
||||
if ($type === 'info') {
|
||||
$iconBorder = '#1D4ED8';
|
||||
$iconBg = 'rgba(29,78,216,.08)';
|
||||
$iconRing = 'rgba(29,78,216,.25)';
|
||||
$iconBg = 'rgba(29,78,216,.08)';
|
||||
$iconRing = 'rgba(29,78,216,.25)';
|
||||
} elseif ($type === 'success') {
|
||||
$iconBorder = '#1E8050';
|
||||
$iconBg = 'rgba(30,128,80,.08)';
|
||||
$iconRing = 'rgba(30,128,80,.20)';
|
||||
$checkCSS = 'width:48px;height:36px;border:5px solid #1e8050;border-top:0;border-left:0;transform:rotate(45deg);';
|
||||
$iconBg = 'rgba(30,128,80,.08)';
|
||||
$iconRing = 'rgba(30,128,80,.20)';
|
||||
$checkCSS = 'width:48px;height:36px;border:5px solid #1e8050;border-top:0;border-left:0;transform:rotate(45deg);';
|
||||
}
|
||||
|
||||
echo '<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">';
|
||||
echo '<title>'.$title.'</title>';
|
||||
echo '<title>' . $title . '</title>';
|
||||
echo '<style>
|
||||
html,body{height:100%;margin:0}
|
||||
body{display:flex;align-items:center;justify-content:center;background:#8CA9FF;font-family:Montserrat,system-ui,Segoe UI,Roboto,Arial}
|
||||
@@ -44,26 +45,26 @@ function ui_exit(string $title, string $message, int $status = 400, string $type
|
||||
</style></head><body><div class="card">';
|
||||
|
||||
// Icône
|
||||
echo '<div style="width:102px;height:102px;border-radius:50%;background:'.$iconBg.';border:3px solid '.$iconRing.';display:flex;align-items:center;justify-content:center;margin:0 auto 20px;">';
|
||||
echo '<div style="width:102px;height:102px;border-radius:50%;background:' . $iconBg . ';border:3px solid ' . $iconRing . ';display:flex;align-items:center;justify-content:center;margin:0 auto 20px;">';
|
||||
if ($type === 'success') {
|
||||
echo '<div style="'.$checkCSS.'"></div>';
|
||||
echo '<div style="' . $checkCSS . '"></div>';
|
||||
} elseif ($type === 'info') {
|
||||
echo '<div style="width:14px;height:48px;border-left:5px solid '.$iconBorder.';position:relative;">
|
||||
<div style="position:absolute;top:-18px;left:-5px;width:10px;height:10px;background:'.$iconBorder.';border-radius:50%;"></div>
|
||||
echo '<div style="width:14px;height:48px;border-left:5px solid ' . $iconBorder . ';position:relative;">
|
||||
<div style="position:absolute;top:-18px;left:-5px;width:10px;height:10px;background:' . $iconBorder . ';border-radius:50%;"></div>
|
||||
</div>';
|
||||
} else { // error
|
||||
echo '<div style="position:relative;width:48px;height:48px;">
|
||||
<div style="position:absolute;top:0;left:22px;width:5px;height:48px;background:'.$iconBorder.';transform:rotate(45deg);border-radius:2px;"></div>
|
||||
<div style="position:absolute;top:0;left:22px;width:5px;height:48px;background:'.$iconBorder.';transform:rotate(-45deg);border-radius:2px;"></div>
|
||||
<div style="position:absolute;top:0;left:22px;width:5px;height:48px;background:' . $iconBorder . ';transform:rotate(45deg);border-radius:2px;"></div>
|
||||
<div style="position:absolute;top:0;left:22px;width:5px;height:48px;background:' . $iconBorder . ';transform:rotate(-45deg);border-radius:2px;"></div>
|
||||
</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo '<h1>'.$title.'</h1>';
|
||||
echo '<p>'.$message.'</p>';
|
||||
echo '<h1>' . $title . '</h1>';
|
||||
echo '<p>' . $message . '</p>';
|
||||
|
||||
if ($cta_href) {
|
||||
echo '<div class="row"><a class="btn btn-outline" href="'.$cta_href.'">'.$cta_label.'</a></div>';
|
||||
echo '<div class="row"><a class="btn btn-outline" href="' . $cta_href . '">' . $cta_label . '</a></div>';
|
||||
}
|
||||
|
||||
echo '</div></body></html>';
|
||||
@@ -76,7 +77,7 @@ function ui_exit(string $title, string $message, int $status = 400, string $type
|
||||
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.",
|
||||
$translations['err_acces_incorrect_msg'] ?? "Cette page doit être appelée depuis le formulaire d'inscription.",
|
||||
405,
|
||||
'info',
|
||||
'inscription_client.php',
|
||||
@@ -105,7 +106,7 @@ if ($nom === '' || $prenom === '' || $email === '' || $mdp === '') {
|
||||
}
|
||||
|
||||
// Email valide + pas d’injection CR/LF
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL) || preg_match('/[\r\n]/', $email)) {
|
||||
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.',
|
||||
@@ -153,38 +154,60 @@ try {
|
||||
'nom' => $nom,
|
||||
'prenom' => $prenom,
|
||||
'email' => $email,
|
||||
'accepted_cgu' => $accept_cgu
|
||||
'accepted_cgu' => $accept_cgu,
|
||||
]);
|
||||
$client_id = (int)$pdo->lastInsertId();
|
||||
$client_id = (int) $pdo->lastInsertId();
|
||||
|
||||
// 2) Créer compte
|
||||
$mot_de_passe_hash = password_hash($mdp, PASSWORD_DEFAULT);
|
||||
$token = bin2hex(random_bytes(32));
|
||||
$token_autologin = bin2hex(random_bytes(32));
|
||||
$token_autologin_expire = (new DateTime('+60 minutes'))->format('Y-m-d H:i:s');
|
||||
|
||||
$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, email_valide, token_autologin, token_autologin_expire)
|
||||
VALUES (:email, :mdp, 'client', :ref_id, :token, 0, :al, :al_exp)
|
||||
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,
|
||||
'al' => $token_autologin,
|
||||
'al_exp' => $token_autologin_expire,
|
||||
]);
|
||||
|
||||
|
||||
$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());
|
||||
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.',
|
||||
@@ -197,7 +220,7 @@ $stmt->execute([
|
||||
// =====================
|
||||
// Email de validation
|
||||
// =====================
|
||||
$validation_url = "https://uslugi.fr/validation.php?token=" . urlencode($token) . "&al=" . urlencode($token_autologin);
|
||||
$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');
|
||||
|
||||
@@ -220,31 +243,31 @@ $html = "<!DOCTYPE html>
|
||||
</head>
|
||||
<body>
|
||||
<div class='mail-container'>
|
||||
<div class='title'>".sprintf($translations['mail_valid_bonjour_nom'], $prenom_nom_safe)."</div>
|
||||
<p>".$translations['mail_valid_merci']."</p>
|
||||
<p>".$translations['mail_valid_action']."</p>
|
||||
<a href='$validation_url_html' class='btn'>".$translations['mail_valid_btn']."</a>
|
||||
<div class='title'>" . sprintf($translations['mail_valid_bonjour_nom'], $prenom_nom_safe) . "</div>
|
||||
<p>" . $translations['mail_valid_merci'] . "</p>
|
||||
<p>" . $translations['mail_valid_action'] . "</p>
|
||||
<a href='$validation_url_html' class='btn'>" . $translations['mail_valid_btn'] . "</a>
|
||||
<p class='link-fallback'>
|
||||
".$translations['mail_valid_fallback']."<br>
|
||||
" . $translations['mail_valid_fallback'] . "<br>
|
||||
<a href='$validation_url_html'>$validation_url_html</a>
|
||||
</p>
|
||||
<div class='footer'>
|
||||
".$translations['mail_valid_expire']."<br>
|
||||
".$translations['mail_valid_ignore']."<br><br>
|
||||
".$translations['mail_valid_signature']."
|
||||
" . $translations['mail_valid_expire'] . "<br>
|
||||
" . $translations['mail_valid_ignore'] . "<br><br>
|
||||
" . $translations['mail_valid_signature'] . "
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>";
|
||||
|
||||
$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".
|
||||
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')
|
||||
);
|
||||
|
||||
@@ -256,7 +279,7 @@ list($sent, $err) = uslugi_mail(
|
||||
$text,
|
||||
['to_name' => "$prenom $nom"]
|
||||
);
|
||||
if (!$sent) {
|
||||
if (! $sent) {
|
||||
error_log("Validation mail NOT sent to $email : $err");
|
||||
// On ne bloque pas l'utilisateur.
|
||||
}
|
||||
@@ -266,7 +289,7 @@ if (!$sent) {
|
||||
// =====================
|
||||
echo '
|
||||
<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>'.htmlspecialchars($translations['insc_merci_titre'] ?? 'Merci !', ENT_QUOTES, 'UTF-8').'</title>
|
||||
<title>' . htmlspecialchars($translations['insc_merci_titre'] ?? 'Merci !', ENT_QUOTES, 'UTF-8') . '</title>
|
||||
<style>
|
||||
html,body{height:100%;margin:0}
|
||||
body{display:flex;align-items:center;justify-content:center;background:#8CA9FF;font-family:Montserrat,system-ui,Segoe UI,Roboto,Arial}
|
||||
@@ -282,11 +305,11 @@ echo '
|
||||
<div style="width:102px;height:102px;border-radius:50%;background:rgba(30,128,80,.08);border:3px solid rgba(30,128,80,.20);display:flex;align-items:center;justify-content:center;margin:0 auto 20px;">
|
||||
<div style="width:48px;height:36px;border:5px solid #1e8050;border-top:0;border-left:0;transform:rotate(45deg);"></div>
|
||||
</div>
|
||||
<h1>'.htmlspecialchars($translations['insc_merci_titre'] ?? 'Merci !', ENT_QUOTES, 'UTF-8').'</h1>
|
||||
<p>'.htmlspecialchars($translations['insc_merci_ligne1'] ?? 'Votre compte a bien été créé.', ENT_QUOTES, 'UTF-8').'</p>
|
||||
<p>'.htmlspecialchars($translations['insc_merci_ligne2'] ?? 'Vérifiez vos emails pour valider votre adresse.', ENT_QUOTES, 'UTF-8').'</p>
|
||||
<h1>' . htmlspecialchars($translations['insc_merci_titre'] ?? 'Merci !', ENT_QUOTES, 'UTF-8') . '</h1>
|
||||
<p>' . htmlspecialchars($translations['insc_merci_ligne1'] ?? 'Votre compte a bien été créé.', ENT_QUOTES, 'UTF-8') . '</p>
|
||||
<p>' . htmlspecialchars($translations['insc_merci_ligne2'] ?? 'Vérifiez vos emails pour valider votre adresse.', ENT_QUOTES, 'UTF-8') . '</p>
|
||||
<div class="row">
|
||||
<a class="btn btn-outline" href="/">'.htmlspecialchars($translations['retour_acceuil'] ?? 'Retour à l’accueil', ENT_QUOTES, 'UTF-8').'</a>
|
||||
<a class="btn btn-outline" href="/">' . htmlspecialchars($translations['retour_acceuil'] ?? 'Retour à l’accueil', ENT_QUOTES, 'UTF-8') . '</a>
|
||||
</div>
|
||||
</div>
|
||||
</body></html>';
|
||||
Reference in new issue
Block a user