ADD: ajout de méthodes dans le user controller

master
Lucie Bedouret 2 years ago
parent 3213fb20e6
commit a2acad71ca

@ -11,29 +11,62 @@ class UserController{
try{ try{
$action = $_REQUEST['action']??null; $action = $_REQUEST['action']??null;
switch($action){ switch($action){
case NULL:
$this->reinit();
break;
case "deconnection": case "deconnection":
$this->deconnection($arrayErrorViews); $this->deconnection($arrayErrorViews);
break; break;
case "creerListePrivee": case "creerListePv":
$this->creerListe($arrayErrorViews); $this->creerListe($arrayErrorViews);
break; break;
case "supprListe": case "desinscription":
$this->supprListe($arrayErrorViews); $this->desinctription($arrayErrorViews);
break;
case "changerInfos":
$this->changerInfos($arrayErrorViews);
break; break;
case "cocherTache":
default : default :
$arrayErrorViews[]="Erreur innatendue !!!"; $arrayErrorViews[]="Erreur innatendue !!!";
require($rep.$vues['error']); require($rep.$vues['error']);
} }
*/
}catch(PDOException $e){ }catch(PDOException $e){
$dataView[]="Erreur inatendue"; $dataView[]="Erreur inatendue";
require(__DIR__.'/../vues/erreur.php'); require($rep.$vues['erreur']);
} }
} }
public function deconnection($arrayErrorViews){
// appeler la méthode deco du modèle
UserModel::deconnection();
}
public function creerListePv($arrayErrorViews){
global $rep, $vues;
//recupérer les valeurs du formulaire
$nomListe=$_POST['ListName'];
$privee=$_POST['isPrivate'];
// valider les champs
Validation::val_creation_Liste_PV($nomListe, $arrayErrorViews);
// vider les champs
//Validation::clear_string($_POST['ListName']);
// appelle à la methode du modèle
if($privee == true){
UserModel::creerListePv($nomListe,$_SESSION['login']);
}else{
VisitorModel::creerListe($nomListe);
}
}
public function desinscription($arrayErrorViews){
global $rep, $vues;
// recup valeurs des champs
$password=$_POST['password'];
// valider les champs
Validation::val_desinscription($password);
// vider les champs
//Validation::clear_string($_POST['password']);
// appel à la classe userModel
UserModel::desinscription($_SESSION['login']);
}
} }
?> ?>

@ -29,7 +29,7 @@ class VisitorController {
} }
}catch(PDOException $e){ }catch(PDOException $e){
$dataView[]="Erreur inatendue"; $dataView[]="Erreur inatendue";
require(__DIR__.'/../vues/erreur.php'); require($rep.$vues['erreur']);
} }
} }

@ -3,8 +3,8 @@
class FrontControleur{ class FrontControleur{
public function __construct(){ public function __construct(){
$liste_actions_utilisateur = array('deconnecter','crerListePrivee','supprListeprivee'); $liste_actions_utilisateur = array('deconnection','crerListePv','desinscription','changerInfos');
$liste_actions_visiteur = array('ajoutListe','suprrListe','connecter'); $liste_actions_visiteur = array('creerListe','suprrListe','connection','inscription','creerTache','cocherTache','supprTache');
global $rep,$vues; global $rep,$vues;
require($rep.$vues['acceuil']); require($rep.$vues['acceuil']);
try{ try{

@ -91,6 +91,40 @@ class ListeGateway {
} }
} }
} }
public function creerListe(string $nom, int $idCreator){
try{
$co = $this->co;
$insertQuery = "INSERT INTO Liste VALUES (NULL, :nom, :idCreator)";
$co->executeQuery($query, array('id' => array($id, PDO::PARAM_INT),
'nom' => array($nom, PDO::PARAM_STR),
'idCreator' => array($idCreator, PDO::PARAM_INT)));
}
catch(PDOException $Exception){
echo 'erreur';
echo $Exception->getMessage();
}
}
}
public function delListe(int $id){
if(!empty($id)){
try{
$co = $this->co;
$query = "DELETE FROM Tache WHERE id=:id";
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
}
catch(PDOException $Exception){
echo 'erreur';
echo $Exception->getMessage();
}
}
}
} }
?> ?>

@ -115,38 +115,6 @@ class UserGateway {
return $usr; return $usr;
} }
public function creerListe(int $id, string $nom){
if(!empty($id) && !empty($nom)){
try{
$co = $this->co;
$query = "INSERT INTO Liste VALUES (:id, :nom, :taches)";
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR), ':nom' => array($nom, PDO::PARAM_STR), ':taches' => array($taches, PDO::PARAM_STR)));
}
catch(PDOException $Exception){
echo 'erreur';
echo $Exception->getMessage();
}
}
}
public function delListe(int $id){
if(!empty($id)){
try{
$co = $this->co;
$query = "DELETE FROM Tache WHERE id=:id";
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
}
catch(PDOException $Exception){
echo 'erreur';
echo $Exception->getMessage();
}
}
}
} }
?> ?>

@ -0,0 +1,28 @@
<?php
class UserModel{
public $listgw;
public $usergw;
public function __construct(){
$co = new Connection();
$this->usergw = new UserGateway($co);
$this->listgw = new ListeGateway($co);
}
public function deconnection(){
session_unset();
session_destroy();
$_SESSION = array();
}
public function creerListePv($nom,$idCeator){
$this->listgw->creerListe($nom,$idCreator);
}
public function desinscription($login){
$this->usergw->delUtilisateur($login);
}
}
?>

@ -7,10 +7,7 @@ class VisitorModel{
$co = new Connection(); $co = new Connection();
$this->gw = new ListeGateway($co); $this->gw = new ListeGateway($co);
} }
public function creerListe(){
}
} }
?> ?>

@ -3,7 +3,7 @@
class Liste { class Liste {
private int $id; private int $id;
private string $nom; private string $nom;
private $taches; private int $idCreator;
function __construct(int $i, string $n, $t){ function __construct(int $i, string $n, $t){
$this->id=$i; $this->id=$i;
@ -19,7 +19,7 @@ class Liste {
return $this->nom; return $this->nom;
} }
function get_taches(): array { function get_idCreator(): array {
return $this->taches; return $this->taches;
} }
} }

@ -5,6 +5,7 @@ Class Tache {
private string $intitule; private string $intitule;
private boolean $isCompleted; private boolean $isCompleted;
private string $description; private string $description;
private int $idListe;
function __construct(int $i, string $in, boolean $is, string $desc){ function __construct(int $i, string $in, boolean $is, string $desc){
$this->id = $i; $this->id = $i;
@ -28,6 +29,10 @@ Class Tache {
function get_description(): string { function get_description(): string {
return $this->description; return $this->description;
} }
function get_idListe(): string {
return $this->idListe;
}
} }
?> ?>

@ -1,27 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>connection</title>
<link rel="stylesheet" href="styles/commonStyles.css">
</head>
<body>
<header>
<h1>You are back ?!</h1>
</header>
<div>
<h4>Username</h4>
<input type="text"/>
<h4>Password</h4>
<input type="password"/>
<br/>
<br/>
<input type="button" value="Log In"/>
<br/>
<br/>
<p>You are new here?</p>
<a href="./signUp.html">
<input type="button" value="Sign Up"/>
</a>
</div>
</body>
</html>

@ -1,8 +0,0 @@
<!DOCTYPE html>
<html>
<div>
<h3>Error!</h3>
<p>There was an error in the fields you filled...</p>
<p>Please enter correct values</p>
</div>
</html>

@ -1,27 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>connection</title>
<link rel="stylesheet" href="styles/commonStyles.css">
</head>
<body>
<header>
<h1>Join the good side of the force</h1>
</header>
<div>
<p>Please enter all the informations :</p>
<h4>Username</h4>
<input type="text"/>
<h4>Password</h4>
<input type="password"/>
<h4>Email</h4>
<input type="email"/>
<h4>Date Of Birth</h4>
<input type="date"/>
<br/>
<br/>
<input type="button" value="Sign Up"/>
</div>
</body>
</html>

@ -1,26 +0,0 @@
header{
display: flex;
flex-direction: row;
background-color: #0971C9;
}
body{
background-color: #0D2350;
}
h1,h2,h3,h4,p{
font-family: sans-serif;
font-weight: bolder;
color: #6da8e2;
}
.button{
width: 150%;
height: 75%;
background-color: #FFFEFD;
border-radius: 20%;
border-color: #0971C9;
color: #0D2350;
}
.button:hover{
background-color: grey;
}
Loading…
Cancel
Save