forked from ghouar-t/SaeDEV2.2
106 lines
4.7 KiB
PHP
106 lines
4.7 KiB
PHP
<?php
|
|
require_once 'common.php';
|
|
session_start();
|
|
|
|
$db = initDatabase();
|
|
|
|
// Populate initial data if table is empty
|
|
$vide = mysqli_query($db, "SELECT * FROM user");
|
|
if (mysqli_num_rows($vide) == 0) {
|
|
$hello = password_hash('hello', PASSWORD_DEFAULT);
|
|
mysqli_query($db, "INSERT INTO user (login, email, last_name, first_name, gender, password, role) VALUES ('toto','toto@gmail.com','Dufour','Michel','homme','$hello','athlete')");
|
|
mysqli_query($db, "INSERT INTO user (login, email, last_name, first_name, gender, password, role) VALUES ('commun','commun@gmail.com','Hello','World','autre','$hello','organizer')");
|
|
mysqli_query($db, "INSERT INTO user (login, email, last_name, first_name, gender, password, role) VALUES ('Marie','Marie@gmail.com','Monro','Mariline','femme','$hello','spectator')");
|
|
}
|
|
|
|
if (!empty($_POST['login']) && !empty($_POST['password'])) {
|
|
$login = htmlspecialchars($_POST['login'], ENT_QUOTES, 'UTF-8');
|
|
$password = htmlspecialchars($_POST['password'], ENT_QUOTES, 'UTF-8');
|
|
$role = htmlspecialchars($_POST['role'], ENT_QUOTES, 'UTF-8');
|
|
$mail = htmlspecialchars($_POST['mail'], ENT_QUOTES, 'UTF-8');
|
|
$nom = htmlspecialchars($_POST['nom'], ENT_QUOTES, 'UTF-8');
|
|
$prenom = htmlspecialchars($_POST['prenom'], ENT_QUOTES, 'UTF-8');
|
|
$genre = htmlspecialchars($_POST['genre'], ENT_QUOTES, 'UTF-8');
|
|
$password_hash = password_hash($password, PASSWORD_DEFAULT);
|
|
|
|
// Check for existing user with same login or email
|
|
$stmt = $db->prepare("SELECT * FROM user WHERE login = ? OR mail = ?");
|
|
$stmt->bind_param("ss", $login, $mail);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
if ($result->num_rows == 0) {
|
|
$stmt = $db->prepare("INSERT INTO user (login, mail, nom, prenom, genre, mdp, Role) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
|
$stmt->bind_param("sssssss", $login, $mail, $nom, $prenom, $genre, $password_hash, $role);
|
|
|
|
if ($stmt->execute()) {
|
|
header('Location: connexion.php');
|
|
exit();
|
|
} else {
|
|
die("Erreur : " . $stmt->error);
|
|
}
|
|
} else {
|
|
$existant = $result->fetch_assoc();
|
|
if ($existant['login'] == $login) {
|
|
$error_verif = "Ce login est déjà utilisé";
|
|
} else if ($existant['mail'] == $mail) {
|
|
$error_verif2 = "Cette adresse mail est déjà utilisée";
|
|
}
|
|
}
|
|
$stmt->close();
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<link rel="icon" href="../img/jo2024.jpg">
|
|
<link rel="stylesheet" href="../css/style.css">
|
|
<title>Inscription - Jeux Olympiques</title>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<h1 class='Hello'>Page d'inscription</h1>
|
|
<nav>
|
|
<a href="../" class="categorie">Page d'accueil</a>
|
|
</nav>
|
|
</header>
|
|
<div class="inscription" id="inscription">
|
|
<u><i><h2>Inscription</h2></i></u> <br>
|
|
<form action="" method="post">
|
|
<label for="login">Login :</label><br>
|
|
<input type="text" id="login" name="login" required><br>
|
|
<?php if (isset($error_verif)) {echo "<div class='error-message'>$error_verif</div>";} ?>
|
|
<br><br><label for="mail">Adresse mail :</label><br>
|
|
<input type="email" id="mail" name="mail" placeholder="username@example.com" required><br>
|
|
<?php if (isset($error_verif2)) {echo "<div class='error-message'>$error_verif2</div>";} ?>
|
|
<br><br><label for="nom">Nom :</label><br>
|
|
<input type="text" id="nom" name="nom" required><br>
|
|
<br><br><label for="prenom">Prenom :</label><br>
|
|
<input type="text" id="prenom" name="prenom" required><br>
|
|
<br><br> <label for="genre"> Genre: </label> <br>
|
|
<select id="genre" name="genre" required>
|
|
<option value="">-- Please choose an option --</option>
|
|
<option value="homme">Homme</option>
|
|
<option value="femme">Femme</option>
|
|
<option value="autre">Autre</option>
|
|
</select><br>
|
|
<br><br><label for="password">Mot de passe :</label><br>
|
|
<input type="password" id="password" name="password" placeholder="••••••••" required><br>
|
|
<br><br><label for="role">Role :</label><br>
|
|
<select id="role" name="role" required>
|
|
<option value="">-- Please choose an option --</option>
|
|
<option value="spectator">Spectator</option>
|
|
<option value="athlete">Athlete</option>
|
|
<option value="organizer">Organizer</option>
|
|
</select><br><br>
|
|
<br><button type="submit" class="submit">Créer un compte</button>
|
|
</form>
|
|
<p class="compteUser">Vous possédez déjà un compte ? <br><a href="connexion.php">Connectez-vous !</a></p>
|
|
</div>
|
|
<footer>
|
|
<?php require_once('footer.php'); ?>
|
|
</footer>
|
|
</body>
|
|
</html>
|