débugage connexion et connexion avec la bd de flavien

This commit is contained in:
remi.biette 2019-04-18 19:36:20 +02:00
parent 4c6537f4d3
commit 5bcf010f4f
4 changed files with 26 additions and 16 deletions

View File

@ -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;
}

View File

@ -6,18 +6,31 @@ require("connectionBD.php");
$db = connexionBD();
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){
$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(){
</div>
<?php
if(isset($_GET['error'])){
$erreur = $_GET['error'];
$erreur = getError($_GET['error']);
echo "<p class = 'error'>$erreur</p>";
}
?>

View File

@ -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'])){

View File

@ -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