200 lines
12 KiB
PHP
200 lines
12 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: auth.php');
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
$user_id = $_SESSION['user_id'];
|
|
$error = '';
|
|
$success = '';
|
|
|
|
// Fetch current user data
|
|
$stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$user = $stmt->fetch();
|
|
|
|
// Fetch available titles
|
|
$stmt = $db->prepare("SELECT * FROM titles WHERE (allowed_user_type = 'all' OR allowed_user_type = ?) AND required_level <= ? ORDER BY name ASC");
|
|
$stmt->execute([$user['user_type'] ?? 'user', $user['level_id'] ?? 1]);
|
|
$available_titles = $stmt->fetchAll();
|
|
|
|
// Fetch available badges
|
|
$stmt = $db->prepare("SELECT * FROM badges WHERE (allowed_user_type = 'all' OR allowed_user_type = ?) AND required_level <= ? ORDER BY name ASC");
|
|
$stmt->execute([$user['user_type'] ?? 'user', $user['level_id'] ?? 1]);
|
|
$available_badges = $stmt->fetchAll();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$action = $_POST['action'] ?? '';
|
|
if ($action === 'update_profile') {
|
|
$email = trim($_POST['email'] ?? '');
|
|
$current_password = $_POST['current_password'] ?? '';
|
|
$new_password = $_POST['new_password'] ?? '';
|
|
$confirm_password = $_POST['confirm_password'] ?? '';
|
|
if (empty($email)) { $error = 'L\'email ne peut pas être vide.'; }
|
|
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error = 'Email invalide.'; }
|
|
elseif (!password_verify($current_password, $user['password'])) { $error = 'Mot de passe actuel incorrect.'; }
|
|
else {
|
|
$sql = "UPDATE users SET email = ?";
|
|
$params = [$email];
|
|
if (!empty($new_password)) {
|
|
if ($new_password !== $confirm_password) { $error = 'Les nouveaux mots de passe ne correspondent pas.'; }
|
|
else { $sql .= ", password = ?"; $params[] = password_hash($new_password, PASSWORD_DEFAULT); }
|
|
}
|
|
$sql .= " WHERE id = ?";
|
|
$params[] = $user_id;
|
|
$stmt = $db->prepare($sql);
|
|
$stmt->execute($params);
|
|
$success = 'Profil mis à jour avec succès.';
|
|
$stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$user = $stmt->fetch();
|
|
}
|
|
} elseif ($action === 'update_display_name') {
|
|
$display_name = trim($_POST['display_name'] ?? '');
|
|
$selected_title_id = $_POST['selected_title_id'] ?? null;
|
|
$selected_badge_id = $_POST['selected_badge_id'] ?? null;
|
|
if ($selected_title_id === '') $selected_title_id = null;
|
|
if ($selected_badge_id === '') $selected_badge_id = null;
|
|
if (!empty($display_name)) {
|
|
$stmt = $db->prepare("UPDATE users SET display_name = ?, selected_title_id = ?, selected_badge_id = ? WHERE id = ?");
|
|
$stmt->execute([$display_name, $selected_title_id, $selected_badge_id, $user_id]);
|
|
$_SESSION["display_name"] = $display_name;
|
|
$success = "Informations mises à jour.";
|
|
$stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$user = $stmt->fetch();
|
|
} else { $error = 'Le nom affiché ne peut pas être vide.'; }
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Mon Compte - Nexus</title>
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
|
|
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
|
|
<style>
|
|
body { background: #000; color: #fff; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; }
|
|
#main-wrapper { display: flex; flex-direction: column; min-height: 100vh; }
|
|
.container { max-width: 700px; margin: 40px auto; padding: 0 20px; flex-grow: 1; width: 100%; box-sizing: border-box; }
|
|
.account-card { background: rgba(30, 41, 59, 0.4); border: 1px solid #1e293b; padding: 30px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
|
|
h2 { color: #88c0d0; text-transform: uppercase; font-size: 18px; border-bottom: 1px solid #1e293b; padding-bottom: 10px; margin-bottom: 20px; }
|
|
.tabs { display: flex; gap: 10px; margin-bottom: 25px; border-bottom: 1px solid #1e293b; }
|
|
.tab-btn { background: none; border: none; color: #64748b; cursor: pointer; padding: 10px 15px; font-weight: bold; font-size: 13px; text-transform: uppercase; transition: all 0.2s; }
|
|
.tab-btn.active { color: #88c0d0; border-bottom: 2px solid #88c0d0; }
|
|
.tab-content { display: none; }
|
|
.tab-content.active { display: block; }
|
|
.form-group { margin-bottom: 20px; }
|
|
label { display: block; margin-bottom: 8px; color: #94a3b8; font-size: 13px; }
|
|
input, select { width: 100%; padding: 12px; background: rgba(15, 23, 42, 0.8); border: 1px solid #334155; color: #fff; border-radius: 6px; box-sizing: border-box; font-family: inherit; }
|
|
input:focus { outline: none; border-color: #88c0d0; }
|
|
button { width: 100%; padding: 14px; background: #88c0d0; border: none; color: #0f172a; font-weight: bold; cursor: pointer; text-transform: uppercase; border-radius: 6px; transition: all 0.2s; }
|
|
button:hover { background: #81a1c1; transform: translateY(-1px); }
|
|
.alert { padding: 12px; border-radius: 6px; margin-bottom: 20px; font-size: 14px; border: 1px solid transparent; }
|
|
.alert-error { background: rgba(191, 97, 106, 0.1); border-color: #bf616a; color: #bf616a; }
|
|
.alert-success { background: rgba(163, 190, 140, 0.1); border-color: #a3be8c; color: #a3be8c; }
|
|
.badge-preview { margin-top: 15px; text-align: center; background: rgba(0,0,0,0.2); padding: 15px; border: 1px dashed #334155; border-radius: 8px; }
|
|
.badge-preview img { max-width: 80px; max-height: 80px; filter: drop-shadow(0 0 10px rgba(136, 192, 208, 0.3)); }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="main-wrapper">
|
|
<?php require_once 'includes/header.php'; ?>
|
|
|
|
<div class="container">
|
|
<div class="account-card">
|
|
<div class="tabs">
|
|
<button class="tab-btn active" onclick="openTab('overview')">Profil de Jeu</button>
|
|
<button class="tab-btn" onclick="openTab('account')">Sécurité & Compte</button>
|
|
</div>
|
|
|
|
<?php if ($error): ?><div class="alert alert-error"><?php echo $error; ?></div><?php endif; ?>
|
|
<?php if ($success): ?><div class="alert alert-success"><?php echo $success; ?></div><?php endif; ?>
|
|
|
|
<div id="overview" class="tab-content active">
|
|
<h2><i class="fa-solid fa-user-tag"></i> Identité de jeu</h2>
|
|
<form method="POST">
|
|
<input type="hidden" name="action" value="update_display_name">
|
|
<div class="form-group">
|
|
<label>Nom affiché (Public)</label>
|
|
<input type="text" name="display_name" value="<?php echo htmlspecialchars($user['display_name'] ?? ''); ?>" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Titre équipé</label>
|
|
<select name="selected_title_id">
|
|
<option value="">Aucun titre</option>
|
|
<?php foreach ($available_titles as $title): ?>
|
|
<option value="<?php echo $title['id']; ?>" <?php echo ($user['selected_title_id'] == $title['id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($title['name']); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Insigne (Badge)</label>
|
|
<select name="selected_badge_id" id="badge-selector" onchange="updateBadgePreview()">
|
|
<option value="" data-img="">Aucun insigne</option>
|
|
<?php foreach ($available_badges as $badge): ?>
|
|
<option value="<?php echo $badge['id']; ?>" data-img="<?php echo htmlspecialchars($badge['image_url']); ?>" <?php echo ($user['selected_badge_id'] == $badge['id']) ? 'selected' : ''; ?>><?php echo htmlspecialchars($badge['name']); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<div id="badge-preview-container" class="badge-preview" style="display: none;">
|
|
<img id="badge-preview-img" src="" alt="Aperçu">
|
|
</div>
|
|
</div>
|
|
<button type="submit">Enregistrer les changements</button>
|
|
</form>
|
|
</div>
|
|
|
|
<div id="account" class="tab-content">
|
|
<h2><i class="fa-solid fa-shield-halved"></i> Sécurité du compte</h2>
|
|
<form method="POST">
|
|
<input type="hidden" name="action" value="update_profile">
|
|
<div class="form-group">
|
|
<label>Adresse Email</label>
|
|
<input type="email" name="email" required value="<?php echo htmlspecialchars($user['email']); ?>">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Nouveau mot de passe (optionnel)</label>
|
|
<input type="password" name="new_password" placeholder="••••••••">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Confirmer le nouveau mot de passe</label>
|
|
<input type="password" name="confirm_password" placeholder="••••••••">
|
|
</div>
|
|
<div style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #1e293b;">
|
|
<div class="form-group">
|
|
<label style="color: #ebcb8b;">Mot de passe actuel (requis pour valider)</label>
|
|
<input type="password" name="current_password" required placeholder="••••••••">
|
|
</div>
|
|
<button type="submit" style="background: #ebcb8b; color: #0f172a;">Mettre à jour le compte</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function openTab(id) {
|
|
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
|
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
|
document.getElementById(id).classList.add('active');
|
|
event.currentTarget.classList.add('active');
|
|
}
|
|
function updateBadgePreview() {
|
|
const selector = document.getElementById('badge-selector');
|
|
const selectedOption = selector.options[selector.selectedIndex];
|
|
const imgUrl = selectedOption.getAttribute('data-img');
|
|
const previewContainer = document.getElementById('badge-preview-container');
|
|
const previewImg = document.getElementById('badge-preview-img');
|
|
if (imgUrl) { previewImg.src = imgUrl; previewContainer.style.display = 'block'; }
|
|
else { previewContainer.style.display = 'none'; }
|
|
}
|
|
window.onload = function() { updateBadgePreview(); };
|
|
</script>
|
|
</body>
|
|
</html>
|