débugage connexion et connexion avec la bd de flavien

pull/1/head
remi.biette 6 years ago
parent 4c6537f4d3
commit 5bcf010f4f

@ -9,15 +9,10 @@
function connexionBD(){ function connexionBD(){
$host = "localhost"; $host = "localhost";
$dbname = "projetWeb"; $dbname = "projet";
$user = "postgres"; $user = "utilisateur";
$pass = "0000"; $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.");
$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.";
}
return $db; return $db;
} }

@ -6,18 +6,31 @@ require("connectionBD.php");
$db = connexionBD(); $db = connexionBD();
init(); init();
function printError(){
if(isset($_GET['error'])){
$erreur = getError($_GET['error']);
echo "<p class = 'error'>$erreur</p>";
}
}
function getError($code){
switch ($code){
case 1:
return "Adresse mail ou mot de passe invalide.";
}
}
function authentification($db, $mail, $password){ function authentification($db, $mail, $password){
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail)); $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
if ($result){ if ($result){
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
return (!strcmp($row["passwd"], $password)); return (strcmp($row["passwd"], $password)) == 0;
} }
return false; return false;
} }
function init(){ function init(){
global $db;
session_start(); session_start();
if(!isset($_SESSION['mail'])){ if(!isset($_SESSION['mail'])){
@ -31,7 +44,7 @@ function init(){
header('Location: tableauBord/tableauBord.php'); header('Location: tableauBord/tableauBord.php');
} }
else { 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(){
</div> </div>
<?php <?php
if(isset($_GET['error'])){ if(isset($_GET['error'])){
$erreur = $_GET['error']; $erreur = getError($_GET['error']);
echo "<p class = 'error'>$erreur</p>"; echo "<p class = 'error'>$erreur</p>";
} }
?> ?>

@ -28,7 +28,7 @@ function isMailUnique($db, $mail){
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail)); $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE mail = $1;", array($mail));
if($result){ if($result){
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
return strcmp($row['mail'], $mail); return (strcmp($row['mail'], $mail) != 0);
} }
return false; return false;
} }
@ -37,7 +37,7 @@ function isLoginUnique($db, $login){
$result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE login = $1;", array($login)); $result = pg_query_params($db, "SELECT * FROM Utilisateur WHERE login = $1;", array($login));
if($result){ if($result){
$row = pg_fetch_array($result); $row = pg_fetch_array($result);
return strcmp($row['login'], $login); return (strcmp($row['login'], $login) != 0);
} }
return false; return false;
} }
@ -49,6 +49,7 @@ function creerUtilisateur($db, $mail, $password, $prenom, $nom, $login, $phone,
function init(){ function init(){
global $db;
session_start(); session_start();
if(!isset($_SESSION['mail'])){ if(!isset($_SESSION['mail'])){

@ -3,9 +3,10 @@
require ('../connectionBD.php'); require ('../connectionBD.php');
$mail = null; $mail = null;
$db = connexionBD(); $db = connexionBD();
init($mail); init();
function init(&$mail){ function init(){
global $mail;
session_start(); session_start();
//Si on est pas connecté redirection vers la page de connexion //Si on est pas connecté redirection vers la page de connexion

Loading…
Cancel
Save