diff --git a/WEB/connectionBD.php b/WEB/connectionBD.php index 4a94735..1476984 100644 --- a/WEB/connectionBD.php +++ b/WEB/connectionBD.php @@ -9,15 +9,10 @@ function connexionBD(){ $host = "localhost"; - $dbname = "projetWeb"; - $user = "postgres"; - $pass = "0000"; - - $db = pg_connect("host=$host port=5432 dbname=$dbname user=$user password=$pass"); - - if($db == false){ - echo "Erreur lors de la connexion à la base de données."; - } + $dbname = "projet"; + $user = "utilisateur"; + $pass = "-stri-"; + $db = pg_connect("host=$host port=5432 dbname=$dbname user=$user password=$pass") or die("Erreur lors de la connexion à la base de données."); return $db; } diff --git a/WEB/index.php b/WEB/index.php index 66dc921..cdf7a10 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -6,18 +6,31 @@ require("connectionBD.php"); $db = connexionBD(); init(); +function printError(){ + if(isset($_GET['error'])){ + $erreur = getError($_GET['error']); + echo "

$erreur

"; + } +} +function getError($code){ + switch ($code){ + case 1: + return "Adresse mail ou mot de passe invalide."; + } +} function authentification($db, $mail, $password){ $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail)); if ($result){ $row = pg_fetch_array($result); - return (!strcmp($row["passwd"], $password)); + return (strcmp($row["passwd"], $password)) == 0; } return false; } function init(){ + global $db; session_start(); if(!isset($_SESSION['mail'])){ @@ -31,7 +44,7 @@ function init(){ header('Location: tableauBord/tableauBord.php'); } else { - header('Location: index.php?error=Adresse mail ou mot de passe invalide.'); + header('Location: index.php?error=1'); } } } @@ -62,7 +75,7 @@ function init(){ $erreur

"; } ?> diff --git a/WEB/inscription.php b/WEB/inscription.php index ec54328..28bb4d2 100644 --- a/WEB/inscription.php +++ b/WEB/inscription.php @@ -28,7 +28,7 @@ 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); + return (strcmp($row['mail'], $mail) != 0); } return false; } @@ -37,7 +37,7 @@ 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); + return (strcmp($row['login'], $login) != 0); } return false; } @@ -49,6 +49,7 @@ function creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone, function init(){ + global $db; session_start(); if(!isset($_SESSION['mail'])){ diff --git a/WEB/tableauBord/tableauBord.php b/WEB/tableauBord/tableauBord.php index d8c523d..c22ff6b 100644 --- a/WEB/tableauBord/tableauBord.php +++ b/WEB/tableauBord/tableauBord.php @@ -3,9 +3,10 @@ require ('../connectionBD.php'); $mail = null; $db = connexionBD(); - init($mail); + init(); - function init(&$mail){ + function init(){ + global $mail; session_start(); //Si on est pas connecté redirection vers la page de connexion