Files

152 lines
6.7 KiB
PHP

<?php
declare (strict_types = 1);
require_once __DIR__ . '/../includes/bootstrap_global.php';
$message = '';
$messageType = '';
if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
$email = trim($_POST['email'] ?? '');
// On garde le contrôle de format, mais message neutre côté utilisateur
if (! filter_var($email, FILTER_VALIDATE_EMAIL) || preg_match('/[\r\n]/', $email)) {
$message = $translations['mdp_oublie_message_neutre'] ?? 'Si un compte existe pour cette adresse, un code a été envoyé.';
$messageType = 'success';
} else {
$stmt = $pdo->prepare("SELECT id FROM compte WHERE email = :email LIMIT 1");
$stmt->execute(['email' => $email]);
$compte = $stmt->fetch();
if ($compte) {
$code = random_int(100000, 999999);
$_SESSION['reset_email'] = $email;
$_SESSION['reset_code'] = (string) $code;
$_SESSION['reset_time'] = time();
$_SESSION['reset_ttl'] = 600;
$_SESSION['reset_attempts'] = 0;
$sujet = $translations['mail_sujet_code'] ?? 'Code de réinitialisation';
$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'>" . htmlspecialchars($translations['mail_bonjour'] ?? 'Bonjour', ENT_QUOTES, 'UTF-8') . "</div>
<p>" . htmlspecialchars($translations['mail_phrase_code'] ?? 'Voici votre code de réinitialisation :', ENT_QUOTES, 'UTF-8') . "</p>
<div class='code'>" . $codeHtml . "</div>
<p>" . htmlspecialchars($translations['mail_phrase_validite'] ?? 'Ce code est valable pendant un temps limité.', ENT_QUOTES, 'UTF-8') . "</p>
<div class='footer'>" . htmlspecialchars($translations['mail_signature'] ?? 'USLUGI.FR', ENT_QUOTES, 'UTF-8') . "</div>
</div>
</body>
</html>";
$text = strip_tags(
($translations['mail_bonjour'] ?? 'Bonjour') . "\n\n" .
($translations['mail_phrase_code'] ?? 'Voici votre code de réinitialisation :') . "\n" .
$code . "\n" .
($translations['mail_phrase_validite'] ?? 'Ce code est valable pendant un temps limité.') . "\n\n" .
($translations['mail_signature'] ?? 'USLUGI.FR')
);
list($ok, $err) = uslugi_mail($email, $sujet, $html, $text);
if (! $ok) {
error_log("Reset code mail NOT sent to $email : $err");
// on reste neutre côté utilisateur
}
// On peut rediriger seulement si le compte existe
header("Location: verifier_code.php");
exit;
}
// Email inconnu → message neutre, pas de détail
$message = $translations['mdp_oublie_message_neutre'] ?? 'Si un compte existe pour cette adresse, un code a été envoyé.';
$messageType = 'success';
}
}
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title><?php echo htmlspecialchars($translations['mdp_oublie_title'] ?? 'Mot de passe oublié', ENT_QUOTES, 'UTF-8') ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="<?php echo asset('/includes/site_style.css') ?>">
<link rel="stylesheet" href="<?php echo asset('/includes/custom_style.css') ?>">
<link rel="stylesheet" href="<?php echo 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"><?php echo $translations['kak_rabotaet'] ?></a></li>
<li><a href="/about.php"><?php echo $translations['pro_nas'] ?></a></li>
<li><a href="/faq.php"><?php echo $translations['faq'] ?></a></li>
<li><a href="/contact.php"><?php echo $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"><?php echo htmlspecialchars($translations['mdp_oublie_h3'] ?? 'Mot de passe oublié', ENT_QUOTES, 'UTF-8') ?></h3>
<?php if (! empty($message)): ?>
<div class="alert alert-<?php echo $messageType === 'success' ? 'success' : 'danger' ?> py-2">
<?php echo 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="<?php echo htmlspecialchars($translations['placeholder_email'] ?? 'Email', ENT_QUOTES, 'UTF-8') ?>"
required>
</div>
<button type="submit" class="btn btn-primary w-100">
<?php echo htmlspecialchars($translations['btn_envoyer_code'] ?? 'Envoyer le code', ENT_QUOTES, 'UTF-8') ?>
</button>
</form>
</div>
</div>
<footer class="site-footer">
<div class="container">
<p><?php echo $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>