Alpha 0.1

This commit is contained in:
Flatlogic Bot 2026-02-22 00:50:09 +00:00
parent 80577e3944
commit bf569922e9
3 changed files with 349 additions and 2 deletions

169
auth.php Normal file
View File

@ -0,0 +1,169 @@
<?php
require_once 'db/config.php';
session_start();
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'register') {
$username = trim($_POST['username'] ?? '');
$email = trim($_POST['email'] ?? '');
$password = $_POST['password'] ?? '';
$password_confirm = $_POST['password_confirm'] ?? '';
if (empty($username) || empty($email) || empty($password)) {
$error = 'Tous les champs sont obligatoires.';
} elseif ($password !== $password_confirm) {
$error = 'Les mots de passe ne correspondent pas.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = 'Email invalide.';
} else {
$db = db();
// Check if user exists
$stmt = $db->prepare("SELECT id FROM users WHERE username = ? OR email = ?");
$stmt->execute([$username, $email]);
if ($stmt->fetch()) {
$error = 'Ce nom d\'utilisateur ou cet email est déjà utilisé.';
} else {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $db->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
try {
$stmt->execute([$username, $email, $hashed_password]);
$success = 'Compte créé avec succès ! Vous pouvez maintenant vous connecter.';
} catch (Exception $e) {
$error = 'Erreur lors de la création du compte.';
}
}
}
} elseif ($action === 'login') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
if (empty($username) || empty($password)) {
$error = 'Tous les champs sont obligatoires.';
} else {
$db = db();
$stmt = $db->prepare("SELECT * FROM users WHERE username = ?");
$stmt->execute([$username]);
$user = $stmt->fetch();
if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
$_SESSION['username'] = $user['username'];
$_SESSION['role'] = $user['role'];
$db->prepare("UPDATE users SET last_login = CURRENT_TIMESTAMP WHERE id = ?")->execute([$user['id']]);
header('Location: index.php');
exit;
} else {
$error = 'Identifiants incorrects.';
}
}
}
}
if (isset($_GET['logout'])) {
session_destroy();
header('Location: index.php');
exit;
}
$page = $_GET['page'] ?? 'login';
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $page === 'register' ? 'Création de compte' : 'Connexion'; ?></title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
body {
background: #000;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
color: #fff;
background-image: radial-gradient(circle at 50% 50%, #1a2a4a 0%, #000 70%);
background-attachment: fixed;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.auth-container {
background: rgba(10, 15, 30, 0.95);
border: 1px solid #4c566a;
padding: 30px;
width: 100%;
max-width: 400px;
box-shadow: 0 0 20px rgba(0,0,0,0.8);
}
h2 { text-transform: uppercase; color: #88c0d0; border-bottom: 1px solid #4c566a; padding-bottom: 10px; margin-top: 0; text-align: center; }
.form-group { margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; color: #8c92a3; font-size: 14px; }
input { width: 100%; padding: 10px; background: #000; border: 1px solid #4c566a; color: #fff; box-sizing: border-box; }
button { width: 100%; padding: 12px; background: #5e81ac; border: none; color: #fff; font-weight: bold; cursor: pointer; text-transform: uppercase; margin-top: 10px; }
button:hover { background: #81a1c1; }
.alert { padding: 10px; margin-bottom: 15px; font-size: 14px; }
.alert-error { background: rgba(191, 97, 106, 0.2); border: 1px solid #bf616a; color: #bf616a; }
.alert-success { background: rgba(163, 190, 140, 0.2); border: 1px solid #a3be8c; color: #a3be8c; }
.switch-link { text-align: center; margin-top: 15px; font-size: 13px; }
.switch-link a { color: #88c0d0; text-decoration: none; }
.switch-link a:hover { text-decoration: underline; }
.back-link { display: block; text-align: center; margin-top: 20px; color: #4c566a; text-decoration: none; font-size: 12px; }
</style>
</head>
<body>
<div class="auth-container">
<?php if ($page === 'register'): ?>
<h2>Créer un compte</h2>
<?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; ?>
<form method="POST">
<input type="hidden" name="action" value="register">
<div class="form-group">
<label>Nom d\'utilisateur</label>
<input type="text" name="username" required value="<?php echo htmlspecialchars($username ?? ''); ?>">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" required value="<?php echo htmlspecialchars($email ?? ''); ?>">
</div>
<div class="form-group">
<label>Mot de passe</label>
<input type="password" name="password" required>
</div>
<div class="form-group">
<label>Confirmer le mot de passe</label>
<input type="password" name="password_confirm" required>
</div>
<button type="submit">S\'inscrire</button>
</form>
<div class="switch-link"> Déjà un compte ? <a href="?page=login">Se connecter</a> </div>
<?php else: ?>
<h2>Connexion</h2>
<?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; ?>
<form method="POST">
<input type="hidden" name="action" value="login">
<div class="form-group">
<label>Nom d\'utilisateur</label>
<input type="text" name="username" required value="<?php echo htmlspecialchars($username ?? ''); ?>">
</div>
<div class="form-group">
<label>Mot de passe</label>
<input type="password" name="password" required>
</div>
<button type="submit">Entrer dans le nexus</button>
</form>
<div class="switch-link"> Pas encore de compte ? <a href="?page=register">Créer un compte</a> </div>
<?php endif; ?>
<a href="index.php" class="back-link"><i class="fa-solid fa-arrow-left"></i> Retour à la galaxie</a>
</div>
</body>
</html>

View File

@ -1,5 +1,6 @@
<?php
require_once 'db/config.php';
session_start();
$db = db();
$view = isset($_GET['view']) ? $_GET['view'] : 'sector';
@ -98,16 +99,32 @@ function getStatusColor($status, $type = 'planet') {
background: rgba(10, 15, 30, 0.95);
border-bottom: 2px solid #2d3545;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
gap: 10px;
}
.resource-container {
display: flex;
gap: 10px;
flex-wrap: wrap;
justify-content: center;
}
.user-auth-bar {
width: 100%;
display: flex;
justify-content: flex-end;
padding: 0 20px;
box-sizing: border-box;
font-size: 12px;
margin-bottom: 5px;
}
.user-auth-bar a { color: #88c0d0; text-decoration: none; margin-left: 15px; display: flex; align-items: center; gap: 5px; }
.user-auth-bar a:hover { text-decoration: underline; color: #fff; }
.user-auth-bar .username { color: #ebcb8b; font-weight: bold; }
.resource-box {
background: #0a0a0a;
border: 1px solid #3b4252;
@ -273,6 +290,16 @@ function getStatusColor($status, $type = 'planet') {
<body>
<div id="main-wrapper">
<header id="top-bar">
<div class="user-auth-bar">
<?php if (isset($_SESSION['user_id'])): ?>
<span>Bienvenue, <span class="username">@<?php echo htmlspecialchars($_SESSION['username']); ?></span></span>
<a href="profile.php"><i class="fa-solid fa-user-gear"></i> Profil</a>
<a href="auth.php?logout=1" style="color: #bf616a;"><i class="fa-solid fa-right-from-bracket"></i> Déconnexion</a>
<?php else: ?>
<a href="auth.php?page=login"><i class="fa-solid fa-right-to-bracket"></i> Connexion</a>
<a href="auth.php?page=register"><i class="fa-solid fa-user-plus"></i> S'inscrire</a>
<?php endif; ?>
</div>
<div class="resource-container">
<?php foreach($resources as $name => $res): ?>
<div class="resource-box">
@ -389,4 +416,4 @@ function getStatusColor($status, $type = 'planet') {
<a href="admin.php" class="admin-link">Console MJ</a>
</body>
</html>
</html>

151
profile.php Normal file
View File

@ -0,0 +1,151 @@
<?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();
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 {
// Update password if provided
if (!empty($new_password)) {
if ($new_password !== $confirm_password) {
$error = 'Les nouveaux mots de passe ne correspondent pas.';
} else {
$hashed_password = password_hash($new_password, PASSWORD_DEFAULT);
$stmt = $db->prepare("UPDATE users SET email = ?, password = ? WHERE id = ?");
$stmt->execute([$email, $hashed_password, $user_id]);
$success = 'Profil et mot de passe mis à jour avec succès.';
}
} else {
$stmt = $db->prepare("UPDATE users SET email = ? WHERE id = ?");
$stmt->execute([$email, $user_id]);
$success = 'Profil mis à jour avec succès.';
}
// Refresh user data
$stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch();
}
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mon Profil - Nexus</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
body {
background: #000;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
color: #fff;
background-image: radial-gradient(circle at 50% 50%, #1a2a4a 0%, #000 70%);
background-attachment: fixed;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.profile-container {
background: rgba(10, 15, 30, 0.95);
border: 1px solid #4c566a;
padding: 30px;
width: 100%;
max-width: 500px;
box-shadow: 0 0 20px rgba(0,0,0,0.8);
}
h2 { text-transform: uppercase; color: #88c0d0; border-bottom: 1px solid #4c566a; padding-bottom: 10px; margin-top: 0; display: flex; align-items: center; gap: 10px; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 5px; color: #8c92a3; font-size: 14px; }
input { width: 100%; padding: 10px; background: #000; border: 1px solid #4c566a; color: #fff; box-sizing: border-box; }
.password-section { margin-top: 25px; border-top: 1px solid #2d3545; padding-top: 15px; }
.password-section h3 { font-size: 14px; text-transform: uppercase; color: #ebcb8b; margin-top: 0; }
button { width: 100%; padding: 12px; background: #5e81ac; border: none; color: #fff; font-weight: bold; cursor: pointer; text-transform: uppercase; margin-top: 10px; transition: background 0.2s; }
button:hover { background: #81a1c1; }
.alert { padding: 10px; margin-bottom: 20px; font-size: 14px; }
.alert-error { background: rgba(191, 97, 106, 0.2); border: 1px solid #bf616a; color: #bf616a; }
.alert-success { background: rgba(163, 190, 140, 0.2); border: 1px solid #a3be8c; color: #a3be8c; }
.nav-links { display: flex; justify-content: space-between; margin-top: 25px; border-top: 1px solid #2d3545; padding-top: 15px; font-size: 13px; }
.nav-links a { color: #88c0d0; text-decoration: none; }
.nav-links a:hover { text-decoration: underline; }
.username-display { font-size: 18px; color: #81a1c1; margin-bottom: 20px; padding: 5px 10px; background: rgba(0,0,0,0.3); border-radius: 4px; display: inline-block; }
</style>
</head>
<body>
<div class="profile-container">
<h2><i class="fa-solid fa-user-gear"></i> Gestion du Compte</h2>
<div class="username-display">
<i class="fa-solid fa-id-card"></i> @<?php echo htmlspecialchars($user['username']); ?>
</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; ?>
<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="password-section">
<h3>Changer le mot de passe (Optionnel)</h3>
<div class="form-group">
<label>Nouveau mot de passe</label>
<input type="password" name="new_password" placeholder="Laisser vide pour ne pas changer">
</div>
<div class="form-group">
<label>Confirmer le nouveau mot de passe</label>
<input type="password" name="confirm_password">
</div>
</div>
<div class="form-group" style="margin-top: 20px;">
<label>Mot de passe actuel (requis pour valider)</label>
<input type="password" name="current_password" required>
</div>
<button type="submit">Enregistrer les modifications</button>
</form>
<div class="nav-links">
<a href="index.php"><i class="fa-solid fa-arrow-left"></i> Retour au Nexus</a>
<a href="auth.php?logout=1" style="color: #bf616a;"><i class="fa-solid fa-right-from-bracket"></i> Déconnexion</a>
</div>
</div>
</body>
</html>