2019-04-18 18:37:23 +02:00
|
|
|
|
<?php
|
|
|
|
|
|
2019-05-10 10:23:27 +02:00
|
|
|
|
require_once('connexionBD.php');
|
2019-04-18 18:37:23 +02:00
|
|
|
|
|
2019-05-10 10:23:27 +02:00
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
|
|
if (!isset($_SESSION['mail'])) {
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0) {
|
|
|
|
|
echo "<p class='error'>PHP a ignoré les données POST à cause d'une requête dépassant post_max_size (" . ini_get('post_max_size') . ").</p>";
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
if (isset($_POST['mail_field'])) {
|
|
|
|
|
$login = htmlentities(pg_escape_string($_POST['login_field']));
|
|
|
|
|
$password = htmlentities(pg_escape_string($_POST['password']));
|
|
|
|
|
$prenom = htmlentities(pg_escape_string($_POST['prenom']));
|
|
|
|
|
$nom = htmlentities(pg_escape_string($_POST['nom']));
|
|
|
|
|
$dateN = htmlentities(pg_escape_string($_POST['dateN']));
|
|
|
|
|
$mail = strtolower(htmlentities(pg_escape_string($_POST['mail_field'])));
|
|
|
|
|
$phone = htmlentities(pg_escape_string($_POST['phone']));
|
|
|
|
|
|
|
|
|
|
if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
|
header('Location: inscription.php?error=1');
|
|
|
|
|
exit();
|
|
|
|
|
} elseif (!isMailUnique($db, $mail)) {
|
|
|
|
|
header('Location: inscription.php?error=2');
|
|
|
|
|
exit();
|
|
|
|
|
} elseif (!isLoginUnique($db, $login)) {
|
|
|
|
|
header('Location: inscription.php?error=3');
|
|
|
|
|
exit();
|
|
|
|
|
} else {
|
|
|
|
|
uploadAvatar($mail);
|
|
|
|
|
$result = creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, $dateN);
|
|
|
|
|
if ($result) {
|
|
|
|
|
header('Location: index.php');
|
|
|
|
|
} else {
|
|
|
|
|
header('Location: inscription.php?error=6');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
header('Location: tableauBord/tableauBord.php');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function printError()
|
|
|
|
|
{
|
|
|
|
|
if (isset($_GET['error'])) {
|
2019-04-18 18:37:23 +02:00
|
|
|
|
$erreur = getError($_GET['error']);
|
|
|
|
|
echo "<p class = 'error'>$erreur</p>";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 10:23:27 +02:00
|
|
|
|
function getError($code)
|
|
|
|
|
{
|
|
|
|
|
switch ($code) {
|
2019-04-18 18:37:23 +02:00
|
|
|
|
case 1:
|
2019-04-28 14:53:08 +02:00
|
|
|
|
return "L'adresse mail est invalide.";
|
2019-04-18 18:37:23 +02:00
|
|
|
|
case 2:
|
2019-04-28 14:53:08 +02:00
|
|
|
|
return "Cette adresse est déjà associée à un compte.";
|
2019-04-18 18:37:23 +02:00
|
|
|
|
case 3:
|
2019-04-28 14:53:08 +02:00
|
|
|
|
return "Ce login est déjà associé à un compte.";
|
2019-04-18 18:37:23 +02:00
|
|
|
|
case 4:
|
2019-04-28 14:53:08 +02:00
|
|
|
|
return "Le fichier envoyé doit être une image au format PNG.";
|
|
|
|
|
case 5:
|
|
|
|
|
return "La taille de l'image ne doit pas dépasser 2 MB.";
|
|
|
|
|
case 6:
|
|
|
|
|
return "Erreur lors de la création du compte.";
|
|
|
|
|
|
2019-04-18 18:37:23 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 10:23:27 +02:00
|
|
|
|
function isMailUnique($db, $mail)
|
|
|
|
|
{
|
2019-04-18 18:37:23 +02:00
|
|
|
|
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
|
2019-05-10 10:23:27 +02:00
|
|
|
|
if ($result) {
|
2019-04-18 18:37:23 +02:00
|
|
|
|
$row = pg_fetch_array($result);
|
2019-04-18 19:36:20 +02:00
|
|
|
|
return (strcmp($row['mail'], $mail) != 0);
|
2019-04-18 18:37:23 +02:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 10:23:27 +02:00
|
|
|
|
function isLoginUnique($db, $login)
|
|
|
|
|
{
|
2019-04-18 18:37:23 +02:00
|
|
|
|
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE login = $1;", array($login));
|
2019-05-10 10:23:27 +02:00
|
|
|
|
if ($result) {
|
2019-04-18 18:37:23 +02:00
|
|
|
|
$row = pg_fetch_array($result);
|
2019-04-18 19:36:20 +02:00
|
|
|
|
return (strcmp($row['login'], $login) != 0);
|
2019-04-18 18:37:23 +02:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 10:23:27 +02:00
|
|
|
|
function creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, $dateN)
|
|
|
|
|
{
|
2019-04-18 18:37:23 +02:00
|
|
|
|
$result = pg_query_params($db, "INSERT INTO Utilisateur VALUES ($1, $2, $3, $4, $5, $6, to_date($7, 'YYYY/MM/DD'), false);", array($mail, $password, $prenom, $nom, $login, $phone, $dateN));
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 10:23:27 +02:00
|
|
|
|
function uploadAvatar($mail)
|
|
|
|
|
{
|
|
|
|
|
if (isset($_FILES['avatar']) and $_FILES['avatar']['name'] != "") {
|
2019-04-28 14:53:08 +02:00
|
|
|
|
$target_file = "imageProfil/$mail.png";
|
|
|
|
|
$file_tmp = $_FILES['avatar']['tmp_name'];
|
|
|
|
|
$extension = end(explode('.', $_FILES['avatar']['name']));
|
|
|
|
|
$check = getimagesize($file_tmp);
|
2019-05-10 10:23:27 +02:00
|
|
|
|
if ($check === false or !in_array($extension, array('png'))) {
|
2019-04-28 14:53:08 +02:00
|
|
|
|
header('Location: inscription.php?error=4');
|
|
|
|
|
exit();
|
2019-05-10 10:23:27 +02:00
|
|
|
|
} else if ($_FILES['avatar']['size'] > 2 * 1024 * 1024) {
|
2019-04-28 14:53:08 +02:00
|
|
|
|
header('Location: inscription.php?error=5');
|
|
|
|
|
exit();
|
2019-05-10 10:23:27 +02:00
|
|
|
|
} else {
|
2019-04-28 14:53:08 +02:00
|
|
|
|
move_uploaded_file($file_tmp, $target_file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-18 18:37:23 +02:00
|
|
|
|
?>
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="fr">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<link rel="stylesheet" href="index_inscription.css">
|
|
|
|
|
<title>Inscription</title>
|
|
|
|
|
<script src="inscription.js"></script>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
2019-04-28 14:53:08 +02:00
|
|
|
|
<div id="formulaire">
|
|
|
|
|
<h1>Inscription</h1>
|
|
|
|
|
<form method="post" enctype="multipart/form-data" action="inscription.php">
|
|
|
|
|
<div class="line">
|
|
|
|
|
<label for="mail_field">Adresse mail : </label>
|
|
|
|
|
<input id="mail_field" class="form" name="mail_field" type="email" maxlength="100" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="line">
|
|
|
|
|
<label for="login_field">Login : </label>
|
|
|
|
|
<input id="login_field" class="form" name="login_field" type="text" maxlength="50" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="line">
|
|
|
|
|
<label for="password">Mot de passe : </label>
|
|
|
|
|
<input class="form" id="password" name="password" type="password" maxlength="50" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="line">
|
|
|
|
|
<label for="confirmation">Confirmation : </label>
|
|
|
|
|
<input class="form" id="confirmation" name="confirmation" type="password" maxlength="16">
|
|
|
|
|
</div>
|
|
|
|
|
<div class="line">
|
|
|
|
|
<label for="prenom_field">Prénom : </label>
|
|
|
|
|
<input id="prenom_field" class="form" name="prenom" type="text" maxlength="50" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="line">
|
|
|
|
|
<label for="nom_field">Nom : </label>
|
|
|
|
|
<input id="nom_field" class="form" name="nom" type="text" maxlength="50" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="line">
|
|
|
|
|
<label for="dateN_field">Date de naissance : </label>
|
|
|
|
|
<input id="dateN_field" class="form" name="dateN" type="date" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="line">
|
|
|
|
|
<label for="phone_field">Numéro de téléphone : </label>
|
|
|
|
|
<input id="phone_field" class="form" name="phone" type="tel" pattern="[0-9]{10}" maxlength="10" required>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="line">
|
|
|
|
|
<label for="avatar">Image du Profil :</label>
|
|
|
|
|
<input type="file" id="avatar" class="form" name="avatar" accept="image/png">
|
|
|
|
|
</div>
|
|
|
|
|
<?php
|
2019-05-10 10:23:27 +02:00
|
|
|
|
printError();
|
2019-04-28 14:53:08 +02:00
|
|
|
|
?>
|
|
|
|
|
<input id="submit" class="button" type="submit" value="S'inscrire">
|
|
|
|
|
</form>
|
|
|
|
|
<p id="enregistrer">Si vous avez déjà un compte <a href="index.php" title="S'identifier">cliquez ici</a>.</p>
|
|
|
|
|
</div>
|
2019-04-18 18:37:23 +02:00
|
|
|
|
</body>
|
|
|
|
|
</html>
|