fix error functions
This commit is contained in:
parent
1a55ad8382
commit
a92937be62
@ -46,7 +46,7 @@ else{
|
||||
</div>
|
||||
<?php
|
||||
if(isset($_GET['error'])){
|
||||
$erreur = getError($_GET['error']);
|
||||
$erreur = getErrorIndex($_GET['error']);
|
||||
echo "<p class = 'error'>$erreur</p>";
|
||||
}
|
||||
?>
|
||||
|
@ -3,61 +3,62 @@ 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();
|
||||
}
|
||||
}
|
||||
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();
|
||||
header('Location: ../tableauBord/tableauBord.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
@ -106,9 +107,7 @@ else {
|
||||
<label for="avatar">Image du Profil :</label>
|
||||
<input type="file" id="avatar" class="form" name="avatar" accept="image/png, image/jpeg">
|
||||
</div>
|
||||
<?php
|
||||
printError();
|
||||
?>
|
||||
<?php getErrorInscription($_GET['error']); ?>
|
||||
<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>
|
||||
|
@ -167,7 +167,7 @@ if (isset($_POST['login']) || isset($_FILES['avatar'])){
|
||||
<label for="avatar">Image du Profil :</label>
|
||||
<input type="file" id="avatar" class="form" name="avatar" accept="image/png, image/jpeg">
|
||||
</div>
|
||||
<?php printError(); ?>
|
||||
<?php getErrorProfil($_GET['error']); ?>
|
||||
<input id="submit" class="button" type="submit" value="Modifier">
|
||||
</form>
|
||||
</div>
|
||||
|
@ -1,15 +1,30 @@
|
||||
<?php
|
||||
function getError($code){
|
||||
switch ($code){
|
||||
case 1:
|
||||
return "Adresse mail ou mot de passe invalide.";
|
||||
}
|
||||
//geterror de l'index
|
||||
function getErrorIndex($code){
|
||||
switch ($code){
|
||||
case 1:
|
||||
return "Adresse mail ou mot de passe invalide.";
|
||||
}
|
||||
}
|
||||
|
||||
//trouver dans Inscription
|
||||
/*
|
||||
function getError($code)
|
||||
{
|
||||
function getErrorProfil($code){
|
||||
switch ($code) {
|
||||
case 1:
|
||||
return "Ce login est déjà associé à un compte.";
|
||||
case 2:
|
||||
return "Les mots de passe ne correspondent pas.";
|
||||
case 3:
|
||||
return "Erreur lors de la récupération des informations de profil.";
|
||||
case 4:
|
||||
return "Le fichier envoyé doit être une image au format PNG ou JPEG.";
|
||||
case 5:
|
||||
return "La taille de l'image ne doit pas dépasser 2 MB.";
|
||||
case 6:
|
||||
return "Erreur lors de la modification du compte.";
|
||||
}
|
||||
}
|
||||
|
||||
function getErrorInscription($code){
|
||||
switch ($code) {
|
||||
case 1:
|
||||
return "L'adresse mail est invalide.";
|
||||
@ -23,10 +38,8 @@ function getError($code)
|
||||
return "La taille de l'image ne doit pas dépasser 2 MB.";
|
||||
case 6:
|
||||
return "Erreur lors de la création du compte.";
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
function authentification($db, $mail, $password){
|
||||
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
|
||||
@ -155,32 +168,7 @@ function uploadAvatar($mail, $fic){
|
||||
return 0;
|
||||
}
|
||||
|
||||
function printError(){
|
||||
if (isset($_GET['error'])) {
|
||||
$erreur = getErrorProfil($_GET['error']);
|
||||
echo "<p class = 'error'>$erreur</p>";
|
||||
}
|
||||
}
|
||||
|
||||
function getErrorProfil($code){
|
||||
switch ($code) {
|
||||
case 1:
|
||||
return "Ce login est déjà associé à un compte.";
|
||||
case 2:
|
||||
return "Les mots de passe ne correspondent pas.";
|
||||
case 3:
|
||||
return "Erreur lors de la récupération des informations de profil.";
|
||||
case 4:
|
||||
return "Le fichier envoyé doit être une image au format PNG ou JPEG.";
|
||||
case 5:
|
||||
return "La taille de l'image ne doit pas dépasser 2 MB.";
|
||||
case 6:
|
||||
return "Erreur lors de la modification du compte.";
|
||||
}
|
||||
}
|
||||
|
||||
function deluser($delmail){
|
||||
echo "c'est supprimé";
|
||||
/*
|
||||
$requete = "UPDATE public.utilisateur SET (mail, passwd, prenom, nom, login, telephone, datenaissance, estadmin) = ('utilisateur_supprime@local', '', '', '', 'utilisateur_supprime', '', to_date('1970/01/01','YYYY/MM/DD'), false) WHERE mail = '".$delmail."';";
|
||||
marche pas
|
||||
@ -189,13 +177,14 @@ function deluser($delmail){
|
||||
*/
|
||||
|
||||
/*
|
||||
Delete l'utilisateur du reste de la base
|
||||
a faire = array('' => , );Delete l'utilisateur du reste de la base
|
||||
*/
|
||||
|
||||
$requete = "DELETE FROM public.utilisateur WHERE mail = '".$delmail."';";
|
||||
|
||||
pg_query($db, $requete);
|
||||
supprimerAvatar($delmail);
|
||||
if(pg_query($db, $requete)){
|
||||
supprimerAvatar($delmail);
|
||||
echo "c'est supprimé";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user