Merge branch 'master' of https://codefirst.iut.uca.fr/git/nathan.boileau/Scripted
continuous-integration/drone/push Build is passing Details

ServeurDeTest
nathan boileau 2 years ago
commit 95969242cd

@ -0,0 +1,11 @@
<?php
class FrontController
{
function __construct()
{
session_start();
// $role=$_SESSION['role'];
// $action=$_REQUEST['action'];
new UserController();
}
}

@ -1,15 +1,12 @@
<?php <?php
class Controller class UserController
{ {
private Connection $con; private Connection $con;
/** function __construct() {
* @param Connection $con global $dsn, $user, $password;
*/ $this->con=new Connection($dsn, $user, $password);;
function __construct(Connection $con) {
$this->con=$con;
session_start();
try{ try{
global $rep, $vues, $error; global $rep, $vues, $error;
$action=$_REQUEST['action']; $action=$_REQUEST['action'];
@ -49,7 +46,7 @@ class Controller
private function signUp() { private function signUp() {
global $rep, $vues, $sel, $error; global $rep, $vues, $sel, $error;
try { try {
$gateway = new JoueurGateway($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.";
@ -63,41 +60,54 @@ class Controller
$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->getJoueurByEmail($_REQUEST['email']); $j = $gateway->getUtilisateurByEmail($_REQUEST['email']);
if ($j != null) { if ($j->getEmail() != "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);
$joueur = new Joueur($_REQUEST['email'], $_REQUEST['username'], $password); $utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, false);
$gateway->insert($joueur); $gateway->insert($utilisateur);
$_SESSION['connected'] = 'true'; $_SESSION['connected'] = 'true';
$_SESSION['role'] = 'utilisateur';
require ($rep.$vues['main']); require ($rep.$vues['main']);
}catch (Exception $e){ }catch (PDOException $e)
{
$error = "Erreur de connexion à la base de données.";
require ($rep.$vues['erreur']);
}
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 JoueurGateway($this->con); $gateway = new UtilisateurGateway($this->con);
$joueur = $gateway->getJoueurByEmail($_REQUEST['email']); $utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']);
if ($joueur->getEmail() == null){ if ($utilisateur->getEmail() == null){
$error = "Joueur non trouvé."; $error = "Utilisateur non trouvé.";
throw new Exception("Joueur 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']);
if ($estAdmin == true) {
$_SESSION['role'] = "admin";
}
else{
$_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']);
} }
} }
// require error page with given message
private function goToPresentation() { private function goToPresentation() {
global $rep, $vues, $error; global $rep, $vues, $error;

@ -1,6 +1,6 @@
<?php <?php
class JoueurGateway class UtilisateurGateway
{ {
private Connection $con; private Connection $con;
@ -19,24 +19,25 @@ class JoueurGateway
$this->con = $con; $this->con = $con;
} }
public function insert(Joueur $joueur) : void{ public function insert(Utilisateur $utilisateur) : void{
$query = "INSERT INTO Joueur VALUE (:email,:pseudo,:mdp)"; $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':email' => array($joueur->getEmail(),PDO::PARAM_STR), ':email' => array($utilisateur->getEmail(),PDO::PARAM_STR),
':pseudo' => array($joueur->getPseudo(),PDO::PARAM_STR), ':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR),
':mdp' => array($joueur->getMdp(),PDO::PARAM_STR))); ':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR),
':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL)));
} }
public function delete(string $email) : void{ public function delete(string $email) : void{
$query = "DELETE FROM Joueur 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 getJoueurByEmail(string $email) : Joueur{ public function getUtilisateurByEmail(string $email) : Utilisateur{
global $error; global $error;
$query = "SELECT * FROM Joueur 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)
)); ));
@ -45,17 +46,17 @@ class JoueurGateway
$email=$row['email']; $email=$row['email'];
$pseudo=$row['pseudo']; $pseudo=$row['pseudo'];
$mdp=$row['mdp']; $mdp=$row['mdp'];
$estAdmin=$row['estAdmin'];
} }
if ($results == null){ if ($results == null){
$error = "Joueur non trouvé."; return new Utilisateur("null", "null", "null", false);
throw new Exception("Joueur Introuvable");
} }
return new Joueur($email, $pseudo, $mdp); 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 Joueur 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)
)); ));
@ -70,28 +71,28 @@ class JoueurGateway
return $mdp; return $mdp;
} }
/*public function resoudreEnigme(string $idJoueur,Partie $partie){ public function getEstAdminByEmail(string $email) : bool{
$query=" SELECT count(:idJoueur) FROM PasserEnMulti pm, Partie p, global $error;
WHERE p.id=pm.partie $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email";
AND pm.idJoueur = :idJoueur"; $this->con->executeQuery($query, array(
$this->con->executeQuery($query); ':email' => array($email,PDO::PARAM_STR)
$index = $this->con->getResults(); ));
$query =" INSERT INTO PasserEnMulti VALUES (:idJoueur,:idpartie,:idEnigme,TRUE,:tempsPartie)"; $results=$this->con->getResults();
$this->con->executeQuery($query, array( foreach ($results as $row) {
'idJoueur' => array($idJoueur,PDO::PARAM_STR), $estAdmin=$row['estAdmin'];
'idPartie' => array($partie->getIdPartie(),PDO::PARAM_INT), }
'idEnigme' => array($partie->getListeEnigme()[$index]->getIdEnigme,PDO::PARAM_INT), return $estAdmin;
'tempsPartie' => array(getdate()-$partie->getDatePartie()),PDO::PARAM_STR)); }
}*/
public function showAll() : void{ public function showAll() : void{
$query = "SELECT * FROM Joueur"; $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>';
} }
} }

@ -20,6 +20,7 @@ class Enigme
* @param string $solution * @param string $solution
* @param string $test * @param string $test
* @param int $tempsDeResolution * @param int $tempsDeResolution
* @param int $points
*/ */
public function __construct() public function __construct()
{ {

@ -1,21 +1,24 @@
<?php <?php
class Joueur class Utilisateur
{ {
private string $email; private string $email;
private string $pseudo; private string $pseudo;
private string $mdp; private string $mdp;
private bool $estAdmin;
/** /**
* @param string $email * @param string $email
* @param string $pseudo * @param string $pseudo
* @param string $mdp * @param string $mdp
* @param bool $estAdmin
*/ */
public function __construct(string $email, string $pseudo, string $mdp) public function __construct(string $email, string $pseudo, string $mdp, bool $estAdmin)
{ {
$this->email = $email; $this->email = $email;
$this->pseudo = $pseudo; $this->pseudo = $pseudo;
$this->mdp = $mdp; $this->mdp = $mdp;
$this->estAdmin = $estAdmin;
} }
/** /**
@ -66,4 +69,18 @@ class Joueur
$this->mdp = $mdp; $this->mdp = $mdp;
} }
/**
* @return bool
*/
public function getEstAdmin(): bool
{
return $this->estAdmin;
}
/**
* @param bool $estAdmin
*/
public function setEstAdmin(bool $estAdmin): void
{
$this->estAdmin = $estAdmin;
}
} }

@ -1,4 +1,72 @@
window.onload = function () { window.onload = function () {
/*data = [{
type: "line",
xValueFormatString: "Pierre",
dataPoints: [
{ x: 0, y: 0 },
{ x: 1, y: 50 },
{ x: 2, y: 100 },
{ x: 3, y: 150 },
{ x: 4, y: 150 },
{ x: 5, y: 200 },
]
},
{
type: "line",
xValueFormatString: "Noe",
dataPoints: [
{ x: 0, y: 0 },
{ x: 1, y: 100 },
{ x: 2, y: 100 },
{ x: 3, y: 200 },
{ x: 4, y: 250 },
{ x: 5, y: 300 },
]
},
{
type: "line",
xValueFormatString: "Nathan",
dataPoints: [
{ x: 0, y: 0 },
{ x: 1, y: 75 },
{ x: 2, y: 100 },
{ x: 3, y: 150 },
{ x: 4, y: 200 },
{ x: 5, y: 250 },
]
}]*/
v1 = {
type: "line",
xValueFormatString: "Pierre",
dataPoints: [
{ x: 0, y: 0 },
{ x: 1, y: 50 },
{ x: 2, y: 100 },
{ x: 3, y: 150 },
{ x: 4, y: 150 },
{ x: 5, y: 200 },
]
}
v2 = {
type: "line",
xValueFormatString: "Noe",
dataPoints: [
{ x: 0, y: 0 },
{ x: 1, y: 100 },
{ x: 2, y: 100 },
{ x: 3, y: 200 },
{ x: 4, y: 250 },
{ x: 5, y: 300 },
]
}
data = []
data.push(v1);
data.push(v2);
console.log(data);
var chart = new CanvasJS.Chart("chartContainer", { var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true, animationEnabled: true,
zoomEnabled: true, zoomEnabled: true,
@ -7,7 +75,7 @@ window.onload = function () {
text: "Score" text: "Score"
}, },
axisX: { axisX: {
title: "Enigme", title: "Temps",
valueFormatString: "####", valueFormatString: "####",
interval: 1 interval: 1
}, },
@ -22,43 +90,7 @@ window.onload = function () {
verticalAlign: "top", verticalAlign: "top",
fontSize: 16, fontSize: 16,
}, },
data: [{ data
type: "line",
xValueFormatString: "Pierre",
dataPoints: [
{ x: 0, y: 0 },
{ x: 1, y: 50 },
{ x: 2, y: 100 },
{ x: 3, y: 150 },
{ x: 4, y: 150 },
{ x: 5, y: 200 },
]
},
{
type: "line",
xValueFormatString: "Noe",
dataPoints: [
{ x: 0, y: 0 },
{ x: 1, y: 100 },
{ x: 2, y: 100 },
{ x: 3, y: 200 },
{ x: 4, y: 250 },
{ x: 5, y: 300 },
]
},
{
type: "line",
xValueFormatString: "Nathan",
dataPoints: [
{ x: 0, y: 0 },
{ x: 1, y: 75 },
{ x: 2, y: 100 },
{ x: 3, y: 150 },
{ x: 4, y: 200 },
{ x: 5, y: 250 },
]
}
]
}); });
chart.render(); chart.render();
} }

@ -2,10 +2,10 @@
require_once('./Config/Config.php'); require_once('./Config/Config.php');
require_once('./Config/Autoload.php'); require_once('./Config/Autoload.php');
Autoload::charger(); Autoload::charger();
$con = new Connection($dsn, $user, $password);
$control = new Controller($con);
session_regenerate_id(true); $control = new FrontController();
//session_regenerate_id(true);
// session_unset(); // session_unset();
// session_destroy(); // session_destroy();
// $_SESSION = null; // $_SESSION = null;

Loading…
Cancel
Save