Test
continuous-integration/drone/push Build is passing Details

ServeurDeTest
Noé GARNIER 2 years ago
parent a5daa35d32
commit 694f7d20d5

@ -14,8 +14,7 @@ $rep = __DIR__ . '/../';
// $password = 'p'; // $password = 'p';
// SQULITE3 // SQULITE3
$dsn = 'sqlite:/Model/scripted.db'; $dsn = './Model/scripted.db';
// $dsn = './Model/scripted.db';
//Sel de hashage //Sel de hashage
$sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong";

@ -1,21 +1,21 @@
<?php <?php
class Connection extends PDO { // class Connection extends PDO {
private $stmt; // private $stmt;
public function __construct(string $dsn) { // public function __construct(string $dsn) {
parent::__construct($dsn); // parent::__construct($dsn);
echo "connection"; // echo "connection";
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } // $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
public function executeQuery(string $query, array $parameters = []) :bool { // public function executeQuery(string $query, array $parameters = []) :bool {
$this->stmt = parent::prepare($query); // $this->stmt = parent::prepare($query);
foreach ($parameters as $name => $value) { // foreach ($parameters as $name => $value) {
$this->stmt->bindValue($name, $value[0], $value[1]); } // $this->stmt->bindValue($name, $value[0], $value[1]); }
return $this->stmt->execute(); } // return $this->stmt->execute(); }
public function getResults(): array { // public function getResults(): array {
return $this->stmt->fetchall(); // return $this->stmt->fetchall();
} // }
} // }
// class Connection extends SQLite3 // class Connection extends SQLite3
// { // {
@ -23,7 +23,7 @@ class Connection extends PDO {
// private $result; // private $result;
// function __construct($dsn) // function __construct($dsn)
// { // {
// parent::__construct($dsn, SQLITE3_OPEN_READWRITE ); // $this->open($dsn);
// $this->enableExceptions(true); // $this->enableExceptions(true);
// } // }
@ -40,3 +40,10 @@ class Connection extends PDO {
// return $this->result->fetchArray(); // return $this->result->fetchArray();
// } // }
// } // }
class Connection extends SQLite3{
function __construct()
{
$this->open("./Model/scripted.db");
}
}

@ -8,19 +8,19 @@ class UserController
try{ try{
echo "UserController"; echo "UserController";
global $dsn, $rep, $vues, $error; global $dsn, $rep, $vues, $error;
$this->con=new Connection ($dsn); $this->con=new Connection ();
echo "USconection"; echo "USconection";
$action=$_REQUEST['action']; $action=$_REQUEST['action'];
switch($action) { switch($action) {
case NULL: case NULL:
$this->goToHome(); $this->goToHome();
break; break;
case "signUp": // case "signUp":
$this->signUp(); // $this->signUp();
break; // break;
case "login": // case "login":
$this->login(); // $this->login();
break; // break;
case "goToPresentation": case "goToPresentation":
$this->goToPresentation(); $this->goToPresentation();
break; break;
@ -48,72 +48,72 @@ class UserController
} }
} }
private function signUp() { // private function signUp() {
global $rep, $vues, $sel, $error; // global $rep, $vues, $sel, $error;
try { // try {
$gateway = new UtilisateurGateway($this->con); // $gateway = new UtilisateurGateway($this->con);
$validation = new Validation(); // $validation = new Validation();
if (! $validation->ValidateEmail($_REQUEST['email'])) { // if (! $validation->ValidateEmail($_REQUEST['email'])) {
$error = "Email invalides."; // $error = "Email invalides.";
throw (new Exception("Email non valide")); // throw (new Exception("Email non valide"));
} // }
if(! $validation->ValidateUsername($_REQUEST['username'])){ // if(! $validation->ValidateUsername($_REQUEST['username'])){
$error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; // $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux.";
throw(new Exception("Pseudo non valide")); // throw(new Exception("Pseudo non valide"));
} // }
if(! $validation->ValidatePassword($_REQUEST['password'])){ // if(! $validation->ValidatePassword($_REQUEST['password'])){
$error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; // $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères.";
throw(new Exception("Mot de passe non valide")); // throw(new Exception("Mot de passe non valide"));
} // }
$j = $gateway->getUtilisateurByEmail($_REQUEST['email']); // $j = $gateway->getUtilisateurByEmail($_REQUEST['email']);
if ($j != null) { // if ($j != null) {
$error = "Email déjà utilisé."; // $error = "Email déjà utilisé.";
throw (new Exception("Email déjà utilisé")); // throw (new Exception("Email déjà utilisé"));
} // }
$password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); // $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT);
$estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); // $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']);
$Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); // $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin);
$gateway->insert($Utilisateur); // $gateway->insert($Utilisateur);
$_SESSION['connected'] = 'true'; // $_SESSION['connected'] = 'true';
$_SESSION['role'] = 'utilisateur'; // $_SESSION['role'] = 'utilisateur';
require ($rep.$vues['main']); // require ($rep.$vues['main']);
}catch (PDOException $e) // }catch (PDOException $e)
{ // {
$error = "Erreur de connexion à la base de données."; // $error = "Erreur de connexion à la base de données.";
require ($rep.$vues['erreur']); // require ($rep.$vues['erreur']);
} // }
catch (Exception $e){ // catch (Exception $e){
require($rep.$vues['erreur']); // require($rep.$vues['erreur']);
} // }
} // }
private function login(){ // private function login(){
global $rep, $vues, $sel, $error; // global $rep, $vues, $sel, $error;
try { // try {
$gateway = new UtilisateurGateway($this->con); // $gateway = new UtilisateurGateway($this->con);
$Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); // $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']);
if ($Utilisateur->getEmail() == null){ // if ($Utilisateur->getEmail() == null){
$error = "Utilisateur non trouvé."; // $error = "Utilisateur non trouvé.";
throw new Exception("Utilisateur introuvable"); // throw new Exception("Utilisateur introuvable");
} // }
$mdp = $gateway->getMdpByEmail($_REQUEST['email']); // $mdp = $gateway->getMdpByEmail($_REQUEST['email']);
if (password_verify($mdp, $_REQUEST['password'])){ // if (password_verify($mdp, $_REQUEST['password'])){
$error = "Mot de passe incorrect."; // $error = "Mot de passe incorrect.";
throw new Exception("Mot de passe invalide"); // throw new Exception("Mot de passe invalide");
} // }
$estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); // $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']);
if ($estAdmin == true) { // if ($estAdmin == true) {
$_SESSION['role'] = "admin"; // $_SESSION['role'] = "admin";
} // }
else{ // else{
$_SESSION['role'] = "utilisateur"; // $_SESSION['role'] = "utilisateur";
} // }
$_SESSION['connected'] = 'true'; // $_SESSION['connected'] = 'true';
require ($rep.$vues['main']); // require ($rep.$vues['main']);
}catch (Exception $e){ // }catch (Exception $e){
require($rep.$vues['erreur']); // require($rep.$vues['erreur']);
} // }
} // }
private function goToPresentation() { private function goToPresentation() {
global $rep, $vues, $error; global $rep, $vues, $error;

@ -19,81 +19,81 @@ class UtilisateurGateway
$this->con = $con; $this->con = $con;
} }
public function insert(Utilisateur $utilisateur) : void{ // public function insert(Utilisateur $utilisateur) : void{
$query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)"; // $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)";
$this->con->executeQuery($query, array( // $this->con->executeQuery($query, array(
':email' => array($utilisateur->getEmail(),PDO::PARAM_STR), // ':email' => array($utilisateur->getEmail(),PDO::PARAM_STR),
':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR), // ':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR),
':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR), // ':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR),
':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL))); // ':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL)));
} // }
public function delete(string $email) : void{ // public function delete(string $email) : void{
$query = "DELETE FROM utilisateur WHERE email=:email"; // $query = "DELETE FROM utilisateur WHERE email=:email";
$this->con->executeQuery($query, array( // $this->con->executeQuery($query, array(
':email' => array($email ,PDO::PARAM_STR) // ':email' => array($email ,PDO::PARAM_STR)
)); // ));
} // }
public function getUtilisateurByEmail(string $email) : Utilisateur{ // public function getUtilisateurByEmail(string $email) : Utilisateur{
global $error; // global $error;
$query = "SELECT * FROM Utilisateur WHERE email=:email"; // $query = "SELECT * FROM Utilisateur WHERE email=:email";
$this->con->executeQuery($query, array( // $this->con->executeQuery($query, array(
':email' => array($email,PDO::PARAM_STR) // ':email' => array($email,PDO::PARAM_STR)
)); // ));
$results=$this->con->getResults(); // $results=$this->con->getResults();
foreach ($results as $row) { // foreach ($results as $row) {
$email=$row['email']; // $email=$row['email'];
$pseudo=$row['pseudo']; // $pseudo=$row['pseudo'];
$mdp=$row['mdp']; // $mdp=$row['mdp'];
$estAdmin=$row['estAdmin']; // $estAdmin=$row['estAdmin'];
} // }
if ($results == null){ // if ($results == null){
return new Utilisateur("null", "null", "null", false); // return new Utilisateur("null", "null", "null", false);
} // }
return new Utilisateur($email, $pseudo, $mdp, $estAdmin); // return new Utilisateur($email, $pseudo, $mdp, $estAdmin);
} // }
public function getMdpByEmail(string $email) : string{ // public function getMdpByEmail(string $email) : string{
global $error; // global $error;
$query = "SELECT mdp FROM Utilisateur WHERE email=:email"; // $query = "SELECT mdp FROM Utilisateur WHERE email=:email";
$this->con->executeQuery($query, array( // $this->con->executeQuery($query, array(
':email' => array($email,PDO::PARAM_STR) // ':email' => array($email,PDO::PARAM_STR)
)); // ));
$results=$this->con->getResults(); // $results=$this->con->getResults();
foreach ($results as $row) { // foreach ($results as $row) {
$mdp=$row['mdp']; // $mdp=$row['mdp'];
} // }
if ($results == null){ // if ($results == null){
$error = "Mot de passe non trouvé."; // $error = "Mot de passe non trouvé.";
throw new Exception("Mots de passe Incorrect"); // throw new Exception("Mots de passe Incorrect");
} // }
return $mdp; // return $mdp;
} // }
public function getEstAdminByEmail(string $email) : bool{ // public function getEstAdminByEmail(string $email) : bool{
global $error; // global $error;
$query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; // $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email";
$this->con->executeQuery($query, array( // $this->con->executeQuery($query, array(
':email' => array($email,PDO::PARAM_STR) // ':email' => array($email,PDO::PARAM_STR)
)); // ));
$results=$this->con->getResults(); // $results=$this->con->getResults();
foreach ($results as $row) { // foreach ($results as $row) {
$estAdmin=$row['estAdmin']; // $estAdmin=$row['estAdmin'];
} // }
return $estAdmin; // return $estAdmin;
} // }
public function showAll() : void{ // public function showAll() : void{
$query = "SELECT * FROM Utilisateur"; // $query = "SELECT * FROM Utilisateur";
$this->con->executeQuery($query); // $this->con->executeQuery($query);
$results=$this->con->getResults(); // $results=$this->con->getResults();
foreach ($results as $row) { // foreach ($results as $row) {
echo $row['email'] . '</br>'; // echo $row['email'] . '</br>';
echo $row['pseudo'] . '</br>'; // echo $row['pseudo'] . '</br>';
echo $row['mdp'] . '</br>'; // echo $row['mdp'] . '</br>';
echo $row['estAdmin'] . '</br>'; // echo $row['estAdmin'] . '</br>';
} // }
} // }
} }
Loading…
Cancel
Save