From fe89b5b7f6589d061da2cf284072484b7290c08b Mon Sep 17 00:00:00 2001 From: "remi.biette" Date: Sat, 18 May 2019 00:40:45 +0200 Subject: [PATCH] Finalisation page profil et creation de la bibliotheque user.php --- WEB/inscription.php | 148 +++++++++++++------------------- WEB/profil.css | 4 +- WEB/profil.php | 145 +++++++++++-------------------- WEB/ressources/user.php | 133 ++++++++++++++++++++++++++++ WEB/tableauBord/tableauBord.php | 35 +------- 5 files changed, 248 insertions(+), 217 deletions(-) create mode 100644 WEB/ressources/user.php diff --git a/WEB/inscription.php b/WEB/inscription.php index 2bdf50f..ed7bc3d 100644 --- a/WEB/inscription.php +++ b/WEB/inscription.php @@ -1,45 +1,62 @@ 0) { - echo "

PHP a ignoré les données POST à ​​cause d'une requête dépassant post_max_size (" . ini_get('post_max_size') . ").

"; - 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 (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 { - uploadAvatar($mail); - $result = creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, $dateN); - if ($result) { - header('Location: index.php'); + 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 { - header('Location: inscription.php?error=6'); + 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 { +} +else { header('Location: tableauBord/tableauBord.php'); + exit(); } function printError() @@ -69,51 +86,6 @@ function getError($code) } } -function isMailUnique($db, $mail) -{ - $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail)); - if ($result) { - $row = pg_fetch_array($result); - return (strcmp($row['mail'], $mail) != 0); - } - return false; -} - -function isLoginUnique($db, $login) -{ - $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE login = $1;", array($login)); - if ($result) { - $row = pg_fetch_array($result); - return (strcmp($row['login'], $login) != 0); - } - return false; -} - -function creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, $dateN) -{ - $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; -} - -function uploadAvatar($mail) -{ - if (isset($_FILES['avatar']) and $_FILES['avatar']['name'] != "") { - $target_file = "imageProfil/$mail.png"; - $file_tmp = $_FILES['avatar']['tmp_name']; - $extension = end(explode('.', $_FILES['avatar']['name'])); - $check = getimagesize($file_tmp); - if ($check === false or !in_array($extension, array('png'))) { - header('Location: inscription.php?error=4'); - exit(); - } else if ($_FILES['avatar']['size'] > 2 * 1024 * 1024) { - header('Location: inscription.php?error=5'); - exit(); - } else { - move_uploaded_file($file_tmp, $target_file); - } - } -} - ?> @@ -121,19 +93,18 @@ function uploadAvatar($mail) Inscription -

Inscription

- - + +
- - + +
@@ -144,24 +115,24 @@ function uploadAvatar($mail)
- - + +
- - + +
- - + +
- - + +
- +

Si vous avez déjà un compte cliquez ici.

+ \ No newline at end of file diff --git a/WEB/profil.css b/WEB/profil.css index a5c7880..1c8ee65 100644 --- a/WEB/profil.css +++ b/WEB/profil.css @@ -1,7 +1,7 @@ *{ margin: 0; padding: 0; - font-family: Arial; + font-family: "Arial", sans-serif; } #divImgProfil{ @@ -11,7 +11,7 @@ justify-content: center; } -#mail_field, #dateN_field{ +#mail, #dateN{ background-color: lightgray; } diff --git a/WEB/profil.php b/WEB/profil.php index c8f8a8a..f7a65e1 100644 --- a/WEB/profil.php +++ b/WEB/profil.php @@ -1,6 +1,7 @@ 2 * 1024 * 1024) { - header('Location: inscription.php?error=5'); - exit(); - } else { - move_uploaded_file($file_tmp, $target_file); - } -} - -function modifierUtilisateur($db, $prenom, $nom, $login, $phone) -{ - $result = pg_query_params($db, "UPDATE Utilisateur SET prenom = $1, nom = $2, login = $3, telephone = $4;", array($prenom, $nom, $login, $phone)); - return $result; -} - -function getUser($db, $mail) -{ - $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail)); - return pg_fetch_array($result); -} - function printError() { if (isset($_GET['error'])) { @@ -114,16 +79,6 @@ function printError() } } -function isLoginUniqueModifier($db, $mail, $login) -{ - $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE login = $1 AND mail != $2;", array($login, $mail)); - if ($result) { - $row = pg_fetch_array($result); - return (strcmp($row['login'], $login) != 0); - } - return false; -} - function getErrorProfil($code) { switch ($code) { @@ -144,7 +99,6 @@ function getErrorProfil($code) } ?> - @@ -162,15 +116,14 @@ function getErrorProfil($code)
- +
- - + +
- - Login : +
@@ -184,23 +137,23 @@ function getErrorProfil($code) value="" required>
- - Prénom : +
- - Nom : +
- - Date de naissance : +
- - Numéro de téléphone : +
diff --git a/WEB/ressources/user.php b/WEB/ressources/user.php new file mode 100644 index 0000000..14547e2 --- /dev/null +++ b/WEB/ressources/user.php @@ -0,0 +1,133 @@ + 2 * 1024 * 1024) { + return -2; + } else { + if(!move_uploaded_file($file_tmp, $target_file)){ + return -3; + } + } + return 0; +} \ No newline at end of file diff --git a/WEB/tableauBord/tableauBord.php b/WEB/tableauBord/tableauBord.php index 5ae4a4a..944451a 100644 --- a/WEB/tableauBord/tableauBord.php +++ b/WEB/tableauBord/tableauBord.php @@ -1,5 +1,8 @@ = current_date;", array($mail)); @@ -88,14 +69,6 @@ function getAvisNonLus($db, $mail) } } -function getPathImgProfil($mail) -{ - if (file_exists("../imageProfil/$mail.png")) { - return "../imageProfil/$mail.png"; - } - return "../imageProfil/default.svg"; -} - function addVoiture($db, $matricule, $marque, $modele, $nbplaces, $anneefab) { $requete = "INSERT INTO public.voiture (matricule, marque, modele, nbplaces, anneefab, mail) VALUES ('" . $matricule . "','" . $marque . "','" . $modele . "','" . $nbplaces . "','" . $anneefab . "','" . $_SESSION['mail'] . "');"; @@ -146,7 +119,7 @@ function showVoiture($db)

Bienvenue

- +