Files
maria_uslugi/public/client/compte.php
T
2026-03-05 10:25:39 +01:00

145 lines
5.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/../includes/init_client.php';
$success = $erreur = '';
$id = $_SESSION['compte_id'];
$stmt = $pdo->prepare("SELECT email FROM compte WHERE id = ?");
$stmt->execute([$id]);
$compte = $stmt->fetch();
if (!$compte) die($translations['compte_introuvable']);
$email_actuel = $compte['email'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nouvel_email = trim($_POST['email'] ?? '');
$mdp1 = $_POST['mot_de_passe'] ?? '';
$mdp2 = $_POST['confirm_mot_de_passe'] ?? '';
if (!filter_var($nouvel_email, FILTER_VALIDATE_EMAIL)) {
$erreur = $translations['erreur_email_invalide_format'];
} elseif ($mdp1 && ($mdp1 !== $mdp2 || strlen($mdp1) < 8)) {
$erreur = $translations['erreur_mdp_invalide_ou_non_confirme'];
} else {
// Vérifie que l'email n’est pas déjà pris (sauf pour soi)
$stmt = $pdo->prepare("SELECT id FROM compte WHERE email = ? AND id != ?");
$stmt->execute([$nouvel_email, $id]);
if ($stmt->fetch()) {
$erreur = $translations['email_deja_utilise'];
} else {
// Mise à jour
if ($mdp1) {
$hash = password_hash($mdp1, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("UPDATE compte SET email = ?, mot_de_passe = ? WHERE id = ?");
$stmt->execute([$nouvel_email, $hash, $id]);
} else {
$stmt = $pdo->prepare("UPDATE compte SET email = ? WHERE id = ?");
$stmt->execute([$nouvel_email, $id]);
}
$success = $translations['maj_effectuee_succes'];
}
}
}
require_once '../includes/header.php';
?>
<div class="main1">
<div class="container py-5">
<?php if ($erreur): ?>
<div class="alert alert-danger"><?= $erreur ?></div>
<?php endif; ?>
<?php if ($success): ?>
<div class="alert alert-success"><?= $success ?></div>
<?php endif; ?>
<form method="POST" class="shadow p-4 rounded bg-light">
<h2 class="text-center mb-4"> <?= $translations['mes_infos_connexion'] ?></h2>
<div class="mb-3">
<label class="form-label"><?= $translations['label_email'] ?></label>
<input type="email" name="email" value="<?= htmlspecialchars($email_actuel) ?>" required class="form-control">
</div>
<div class="mb-3">
<label class="form-label"><?= $translations['label_nouveau_mdp_facultatif'] ?></label>
<div class="field-wrapper">
<input type="password" name="mot_de_passe" id="mot_de_passe" placeholder="<?= $translations['nouveau_mdp_placeholder'] ?>" class="form-control">
<span class="toggle-password" onclick="toggle('mot_de_passe')">👁️</span>
</div>
</div>
<div class="strength-bar mb-1">
<div class="strength-fill"></div>
<div class="strength-fill"></div>
<div class="strength-fill"></div>
</div>
<div id="niveau-securite" class="mb-3 text-muted"><?= $translations['securite_indetermine'] ?></div>
<div class="mb-4">
<label class="form-label"><?= $translations['label_confirmer_mdp'] ?></label>
<div class="field-wrapper">
<input type="password" name="confirm_mot_de_passe" id="confirm_mot_de_passe" placeholder="<?= $translations['confirm_mdp_placeholder'] ?>" class="form-control">
<span class="toggle-password" onclick="toggle('confirm_mot_de_passe')">👁️</span>
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary"> <?= $translations['btn_mettre_a_jour'] ?></button>
</div>
</form>
</div>
<script>
function toggle(id) {
const el = document.getElementById(id);
el.type = el.type === 'password' ? 'text' : 'password';
}
document.getElementById('mot_de_passe').addEventListener('input', function () {
const val = this.value;
const segments = document.querySelectorAll(".strength-fill");
const niveauText = document.getElementById("niveau-securite");
segments.forEach(s => s.style.backgroundColor = '#e0e0e0');
niveauText.textContent = <?= json_encode($translations['securite_indetermine']) ?>;
niveauText.className = 'text-muted';
const longOk = val.length >= 8;
const lettre = /[A-Za-z]/.test(val);
const chiffre = /\d/.test(val);
const maj = /[A-Z]/.test(val);
const special = /[^A-Za-z0-9]/.test(val);
let force = 0;
if (longOk && lettre && chiffre) force++;
if (maj) force++;
if (special) force++;
if (force === 1) {
segments[0].style.backgroundColor = 'red';
niveauText.textContent = <?= json_encode($translations['securite_faible']) ?>;
niveauText.className = 'text-danger';
} else if (force === 2) {
segments[0].style.backgroundColor = 'orange';
segments[1].style.backgroundColor = 'orange';
niveauText.textContent = <?= json_encode($translations['securite_moyen']) ?>;
niveauText.className = 'text-warning';
} else if (force >= 3) {
segments.forEach(s => s.style.backgroundColor = 'green');
niveauText.textContent = <?= json_encode($translations['securite_fort']) ?>;
niveauText.className = 'text-success';
}
});
</script>
</div>
<footer class="site-footer">
<div class="container">
<p><?= $translations['copyr'] ?></p>
</div>
</footer>
</body>
</html>