diff --git a/db/setup.php b/db/setup.php index 96cfef4..a7f9558 100644 --- a/db/setup.php +++ b/db/setup.php @@ -27,6 +27,59 @@ try { $pdo->exec($sql); echo "Table 'users' created successfully (if it didn't exist).\n"; + // Create servers table + $sql = " + CREATE TABLE IF NOT EXISTS servers ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100) NOT NULL, + owner_id INT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE + );"; + $pdo->exec($sql); + echo "Table 'servers' created successfully.\n"; + + // Create server_members table + $sql = " + CREATE TABLE IF NOT EXISTS server_members ( + id INT AUTO_INCREMENT PRIMARY KEY, + server_id INT NOT NULL, + user_id INT NOT NULL, + joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (server_id) REFERENCES servers(id) ON DELETE CASCADE, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, + UNIQUE KEY (server_id, user_id) + );"; + $pdo->exec($sql); + echo "Table 'server_members' created successfully.\n"; + + // Create channels table + $sql = " + CREATE TABLE IF NOT EXISTS channels ( + id INT AUTO_INCREMENT PRIMARY KEY, + server_id INT NOT NULL, + name VARCHAR(100) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (server_id) REFERENCES servers(id) ON DELETE CASCADE + );"; + $pdo->exec($sql); + echo "Table 'channels' created successfully.\n"; + + // Create messages table + $sql = " + CREATE TABLE IF NOT EXISTS messages ( + id INT AUTO_INCREMENT PRIMARY KEY, + channel_id INT NOT NULL, + user_id INT NOT NULL, + message TEXT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE CASCADE, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE + );"; + $pdo->exec($sql); + echo "Table 'messages' created successfully.\n"; + + } catch (PDOException $e) { die("DB SETUP ERROR: " . $e->getMessage()); } diff --git a/login.php b/login.php index df96634..be40b0b 100644 --- a/login.php +++ b/login.php @@ -11,11 +11,11 @@ if (isset($_SESSION['user_id'])) { $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $username = trim($_POST['username'] ?? ''); + $email = trim($_POST['email'] ?? ''); $password = $_POST['password'] ?? ''; - if (empty($username)) { - $errors[] = 'Le nom d\'utilisateur est requis.'; + if (empty($email)) { + $errors[] = 'L\'adresse e-mail est requise.'; } if (empty($password)) { $errors[] = 'Le mot de passe est requis.'; @@ -24,8 +24,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (empty($errors)) { try { $pdo = db(); - $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?"); - $stmt->execute([$username]); + $stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { @@ -40,7 +40,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { echo ''; exit(); } else { - $errors[] = 'Nom d\'utilisateur ou mot de passe incorrect.'; + $errors[] = 'Adresse e-mail ou mot de passe incorrect.'; } } catch (PDOException $e) { error_log("Login Error: " . $e->getMessage()); @@ -75,8 +75,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {