vault backup: 2026-02-21 15:59:55
This commit is contained in:
48
.trash/contact.html
Normal file
48
.trash/contact.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<div id="contact-area">
|
||||
<div id="step1">
|
||||
<input type="email" id="email" placeholder="Votre email" required><br>
|
||||
<textarea id="message" placeholder="Votre message (10 caractères min.)"></textarea><br>
|
||||
<button onclick="sendCode()">Recevoir un code de validation</button>
|
||||
</div>
|
||||
|
||||
<div id="step2" style="display:none;">
|
||||
<p>Un code a été envoyé à votre adresse. Entrez-le ci-dessous :</p>
|
||||
<input type="text" id="verify_code" placeholder="Code à 6 chiffres">
|
||||
<button onclick="verifyAndSend()">Valider l'envoi définitif</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentToken = "";
|
||||
|
||||
async function sendCode() {
|
||||
const fd = new FormData();
|
||||
fd.append('step', 'send_code');
|
||||
fd.append('email', document.getElementById('email').value);
|
||||
fd.append('message', document.getElementById('message').value);
|
||||
|
||||
const res = await fetch('/contact-verify.php', { method: 'POST', body: fd });
|
||||
const data = await res.json();
|
||||
|
||||
if (data.status === 'success') {
|
||||
currentToken = data.token;
|
||||
document.getElementById('step1').style.display = 'none';
|
||||
document.getElementById('step2').style.display = 'block';
|
||||
} else {
|
||||
alert(data.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyAndSend() {
|
||||
const fd = new FormData();
|
||||
fd.append('step', 'verify_code');
|
||||
fd.append('token', currentToken);
|
||||
fd.append('code', document.getElementById('verify_code').value);
|
||||
|
||||
const res = await fetch('/contact-verify.php', { method: 'POST', body: fd });
|
||||
const data = await res.json();
|
||||
|
||||
alert(data.message);
|
||||
if (data.status === 'success') location.reload();
|
||||
}
|
||||
</script>
|
||||
79
.trash/scripts/send-mail.php
Normal file
79
.trash/scripts/send-mail.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
session_start();
|
||||
$log_dir = "/tmp/contact_auth/";
|
||||
if (!is_dir($log_dir)) mkdir($log_dir, 0700);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// --- CONFIGURATION ---
|
||||
$to_admin = "votre-email@abonnel.fr";
|
||||
$from_server = "webmaster@abonnel.fr";
|
||||
|
||||
$step = $_POST['step'] ?? '';
|
||||
|
||||
// --- ACTION 1 : GÉNÉRATION ET ENVOI DU CODE ---
|
||||
if ($step === 'send_code') {
|
||||
$email = filter_var($_POST['email'] ?? '', FILTER_VALIDATE_EMAIL);
|
||||
$message = trim($_POST['message'] ?? '');
|
||||
|
||||
if (!$email || strlen($message) < 10) {
|
||||
echo json_encode(["status" => "error", "message" => "Données invalides."]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Génération du code
|
||||
$code = rand(100000, 999999);
|
||||
$token = md5($email . time());
|
||||
|
||||
// Stockage temporaire (Valide 1h)
|
||||
$auth_data = [
|
||||
'code' => $code,
|
||||
'email' => $email,
|
||||
'message' => $message,
|
||||
'expires' => time() + 3600
|
||||
];
|
||||
file_put_contents($log_dir . $token, json_encode($auth_data));
|
||||
|
||||
// Envoi du code à l'utilisateur
|
||||
$subject = "Votre code de vérification - abonnel.fr";
|
||||
$body = "Votre code de validation est : $code\nCe code expire dans 1 heure.";
|
||||
|
||||
if (mail($email, $subject, $body, "From: $from_server")) {
|
||||
echo json_encode(["status" => "success", "token" => $token]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "Erreur d'envoi du code."]);
|
||||
}
|
||||
}
|
||||
|
||||
// --- ACTION 2 : VÉRIFICATION ET ENVOI FINAL ---
|
||||
if ($step === 'verify_code') {
|
||||
$token = $_POST['token'] ?? '';
|
||||
$user_code = $_POST['code'] ?? '';
|
||||
$file = $log_dir . $token;
|
||||
|
||||
if (!file_exists($file)) {
|
||||
echo json_encode(["status" => "error", "message" => "Session expirée."]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = json_decode(file_get_contents($file), true);
|
||||
|
||||
if (time() > $data['expires']) {
|
||||
unlink($file);
|
||||
echo json_encode(["status" => "error", "message" => "Code expiré."]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($user_code == $data['code']) {
|
||||
// Envoi final à VOUS
|
||||
$final_subject = "[Validé] Contact de " . $data['email'];
|
||||
$final_body = "Message de : " . $data['email'] . "\n\n" . $data['message'];
|
||||
|
||||
mail($to_admin, $final_subject, $final_body, "From: $from_server\r\nReply-To: " . $data['email']);
|
||||
|
||||
unlink($file); // Supprime le ticket après succès
|
||||
echo json_encode(["status" => "success", "message" => "Message envoyé avec succès !"]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "Code incorrect."]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user