152 lines
5.7 KiB
PHP
152 lines
5.7 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
require_once __DIR__ . '/../includes/bootstrap_global.php';
|
||
|
||
$message = '';
|
||
|
||
if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
|
||
$email = trim($_POST['email'] ?? '');
|
||
|
||
// Email valide + pas d’injection d’en-têtes
|
||
if (!filter_var($email, FILTER_VALIDATE_EMAIL) || preg_match('/[\r\n]/', $email)) {
|
||
$message = $translations['err_email_non_valide'] ?? 'Email invalide.';
|
||
} else {
|
||
// Vérifier si le compte existe
|
||
$stmt = $pdo->prepare("SELECT id FROM compte WHERE email = :email LIMIT 1");
|
||
$stmt->execute(['email' => $email]);
|
||
$compte = $stmt->fetch();
|
||
|
||
if ($compte) {
|
||
// Génère un code à 6 chiffres
|
||
$code = random_int(100000, 999999);
|
||
|
||
// Enregistre en session (TTL 10 minutes)
|
||
$_SESSION['reset_email'] = $email;
|
||
$_SESSION['reset_code'] = $code;
|
||
$_SESSION['reset_time'] = time();
|
||
$_SESSION['reset_ttl'] = 600; // 10 min
|
||
|
||
// Prépare l'e-mail
|
||
$sujet = $translations['mail_sujet_code'];
|
||
$codeHtml = htmlspecialchars((string)$code, ENT_QUOTES, 'UTF-8');
|
||
|
||
$html = "<!DOCTYPE html>
|
||
<html lang='fr'>
|
||
<head>
|
||
<meta charset='UTF-8'>
|
||
<style>
|
||
body { font-family: Arial, sans-serif; background:#f4f4f4; padding:20px; }
|
||
.mail-container { background:#ffffff; padding:30px; border-radius:8px; max-width:600px; margin:auto; box-shadow:0 0 10px rgba(0,0,0,0.1); }
|
||
.title { font-size:20px; margin-bottom:20px; color:#333; }
|
||
.code { font-size:28px; font-weight:bold; color:#0056b3; margin:20px 0; text-align:center; background:#eef3ff; padding:10px 20px; border-radius:6px; display:inline-block; }
|
||
.footer { font-size:13px; color:#777; margin-top:30px; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class='mail-container'>
|
||
<div class='title'>".$translations['mail_bonjour']."</div>
|
||
<p>".$translations['mail_phrase_code']."</p>
|
||
<div class='code'>".$codeHtml."</div>
|
||
<p>".$translations['mail_phrase_validite']."</p>
|
||
<div class='footer'>".$translations['mail_signature']."</div>
|
||
</div>
|
||
</body>
|
||
</html>";
|
||
|
||
$text = strip_tags(
|
||
$translations['mail_bonjour']."\n\n".
|
||
$translations['mail_phrase_code']."\n".
|
||
$code."\n".
|
||
$translations['mail_phrase_validite']."\n\n".
|
||
$translations['mail_signature']
|
||
);
|
||
|
||
// Envoi via PHPMailer helper
|
||
list($ok, $err) = uslugi_mail($email, $sujet, $html, $text);
|
||
if (!$ok) {
|
||
error_log("Reset code mail NOT sent to $email : $err");
|
||
// On reste silencieux pour l’utilisateur
|
||
}
|
||
|
||
header("Location: verifier_code.php");
|
||
exit;
|
||
} else {
|
||
// Ton message existant si l'email est inconnu
|
||
$message = $translations['erreur_email_inconnu'];
|
||
}
|
||
}
|
||
}
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="ru">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title><?= $translations['mdp_oublie_title'] ?></title>
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
||
<link rel="stylesheet" href="<?= asset('/includes/site_style.css') ?>">
|
||
<link rel="stylesheet" href="<?= asset('/includes/custom_style.css') ?>"> <!-- ta home -->
|
||
|
||
<link rel="stylesheet" href="<?= asset('/includes/mobil_style.css') ?>">
|
||
<?php include_once __DIR__ . '/includes/tracking.php'; ?>
|
||
</head>
|
||
<body>
|
||
<header class="site-header">
|
||
<div class="container">
|
||
<div class="header-left">
|
||
<div class="brand">
|
||
<a href="/index.php"><img src="/public/uploads/img/logo_u.png"
|
||
alt="uslugi.fr"
|
||
class="logo-mobile"></a>
|
||
|
||
<a href="/index.php"><img src="/public/uploads/img/logo.png"
|
||
alt="uslugi.fr"
|
||
class="logo-desktop"></a>
|
||
</div>
|
||
<div class="lang-switch">
|
||
<?php require __DIR__ . '/includes/menu_langue.php'; ?>
|
||
</div>
|
||
</div>
|
||
<nav class="header-actions">
|
||
<div class="dropdown">
|
||
<button class="btn btn-logo rounded-circle d-inline-flex align-items-center justify-content-center question-btn"
|
||
type="button" data-bs-toggle="dropdown" data-bs-auto-close="true"
|
||
aria-expanded="false" aria-label="Помощь">?</button>
|
||
<ul class="dropdown-menu dropdown-menu-end shadow help-menu menu-panel">
|
||
<li><a href="/how-it-work.php"><?= $translations['kak_rabotaet'] ?></a></a></li>
|
||
<li><a href="/about.php"><?= $translations['pro_nas'] ?></a></li>
|
||
<li><a href="/faq.php"><?= $translations['faq'] ?></a></li>
|
||
<li><a href="/contact.php"><?= $translations['nam_pisat'] ?></a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
</nav>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="main">
|
||
<div class="card shadow-sm p-4" style="min-width:380px; max-width:520px; margin:40px auto;">
|
||
<h3 class="mb-4 text-center"><?= $translations['mdp_oublie_h3'] ?></h3>
|
||
|
||
<?php if (!empty($message)): ?>
|
||
<div class="alert alert-danger py-2"><?= htmlspecialchars($message, ENT_QUOTES, 'UTF-8') ?></div>
|
||
<?php endif; ?>
|
||
|
||
<form method="POST" novalidate>
|
||
<div class="mb-3">
|
||
<input type="email" name="email" class="form-control" placeholder="<?= $translations['placeholder_email'] ?>" required>
|
||
</div>
|
||
<button type="submit" class="btn btn-primary w-100"><?= $translations['btn_envoyer_code'] ?></button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<footer class="site-footer">
|
||
<div class="container">
|
||
<p><?= $translations['copyr'] ?></p>
|
||
</div>
|
||
</footer>
|
||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||
</body>
|
||
</html>
|