You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
5.4 KiB
PHP
145 lines
5.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once('../connexionBD.php');
|
|
require_once('../ressources/user.php');
|
|
|
|
if (!isset($_SESSION['mail'])) {
|
|
if (isset($_POST['login']) || isset($_FILES['avatar'])) {
|
|
if (isset($_POST['login']) && isset($_POST['password']) && isset($_POST['confirmation']) && isset($_POST['prenom']) && isset($_POST['nom']) && isset($_POST['phone'])) {
|
|
$login = htmlentities(pg_escape_string($_POST['login']));
|
|
$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'])));
|
|
$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 {
|
|
if (isset($_FILES['avatar']) and !empty($_FILES['avatar']['name'])) {
|
|
$fic = $_FILES['avatar'];
|
|
$res = uploadAvatar($mail, $fic);
|
|
switch ($res){
|
|
case -1:
|
|
header('Location: inscription.php?error=4');
|
|
exit();
|
|
case -2:
|
|
header('Location: inscription.php?error=5');
|
|
exit();
|
|
case -3:
|
|
header('Location: inscription.php?error=6');
|
|
exit();
|
|
}
|
|
}
|
|
$result = creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, $dateN);
|
|
if ($result) {
|
|
header('Location: ../index.php');
|
|
exit();
|
|
} else {
|
|
header('Location: inscription.php?error=6');
|
|
exit();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
header('Location: ../tableauBord/tableauBord.php');
|
|
exit();
|
|
}
|
|
|
|
function printError()
|
|
{
|
|
if (isset($_GET['error'])) {
|
|
$erreur = getError($_GET['error']);
|
|
echo "<p class = 'error'>$erreur</p>";
|
|
}
|
|
}
|
|
|
|
function getError($code)
|
|
{
|
|
switch ($code) {
|
|
case 1:
|
|
return "L'adresse mail est invalide.";
|
|
case 2:
|
|
return "Cette adresse est déjà associée à un compte.";
|
|
case 3:
|
|
return "Ce login est déjà associé à un compte.";
|
|
case 4:
|
|
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.";
|
|
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<link rel="stylesheet" href="inscription.css">
|
|
<title>Inscription</title>
|
|
</head>
|
|
<body>
|
|
<div id="formulaire">
|
|
<h1>Inscription</h1>
|
|
<form method="post" enctype="multipart/form-data" action="inscription.php">
|
|
<div class="line">
|
|
<label for="mail">Adresse mail : </label>
|
|
<input id="mail" class="form" name="mail" type="email" maxlength="100" required>
|
|
</div>
|
|
<div class="line">
|
|
<label for="login">Login : </label>
|
|
<input id="login" class="form" name="login" 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">Prénom : </label>
|
|
<input id="prenom" class="form" name="prenom" type="text" maxlength="50" required>
|
|
</div>
|
|
<div class="line">
|
|
<label for="nom">Nom : </label>
|
|
<input id="nom" class="form" name="nom" type="text" maxlength="50" required>
|
|
</div>
|
|
<div class="line">
|
|
<label for="dateN">Date de naissance : </label>
|
|
<input id="dateN" class="form" name="dateN" type="date" required>
|
|
</div>
|
|
<div class="line">
|
|
<label for="phone">Numéro de téléphone : </label>
|
|
<input id="phone" 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, image/jpeg">
|
|
</div>
|
|
<?php
|
|
printError();
|
|
?>
|
|
<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>
|
|
<script src="inscription.js"></script>
|
|
</body>
|
|
</html>
|