Nouvelles classes et corrections

validation, controleurVisiteur, VisiteurModel
corrections
master
Mathilde JEAN 2 years ago
parent a3bc6d1e97
commit 061aa6ed32

@ -0,0 +1,20 @@
<?php
class Validation {
static function val_connexion($usrName,$mdp,&$dataVueEreur) {
if (!isset($usrName)||$usrName=="") {
$dataVueEreur[] ="Nom d'utilisateur manquant";
throw new Exception('pas de username');
}
if (!isset($mdp)||$mdp=="") {
$dataVueEreur[] ="Mot de passe manquant";
throw new Exception('pas de password');
}
}
static function clear_string($champ){
// Wesh
}
}
?>

@ -17,12 +17,22 @@ class VisitorController {
case "connection":
$this->connection($arrayErrorViews);
break;
case "inscription":
$this->inscription($arrayErrorViews);
case "creerListe":
$this->creerListe($arrayErrorViews);
break;
case "supprListe":
$this->supprListe($arrayErrorViews);
break;
case "creerTache":
$this->creerTache($arrayErrorViews);
break;
case "cocherTache":
$this->cocherTache($arrayErrorViews);
break;
case "supprTache":
$this->supprTache($arrayErrorViews);
default :
$arrayErrorViews[]="Erreur innatendue !!!";
require($rep.$vues['error']);
@ -30,7 +40,12 @@ class VisitorController {
} catch(PDOException $e){
$dataView[]="Erreur inatendue";
require(__DIR__.'/../vues/erreur.php');
} catch (Exception $e2)
{
$dVueEreur[] = "Erreur inattendue!!! ";
require ($rep.$vues['erreur']);
}
exit(0);
}
public function reinit(){
@ -40,7 +55,63 @@ class VisitorController {
public function connection(array $vues_erreur){
global $rep,$vues;
require($rep.$vues['connection']);
$usrname=$_POST['login'];
$pwd=$_POST['mdp'];
Validation::clear_string($pwd);
Validation::val_connexion($usrname,$pwd,$vues_erreur);
$model = new UserModel();
$worked=$model->connexion();
/*
$dVue = array (
'username' => $usrname,
'password' => $pwd,
'worked' => $worked,
);
*/
if($worked==false){
require('erreur.php');
}
}
public function inscription(array $vues_erreur){
global $rep,$vues;
$usrname=$_POST['login'];
$pwd=$_POST['mdp'];
Validation::val_connexion($usrname,$pwd,$vues_erreur);
$model = new UserModel();
$model->inscription();
}
public function creerListe(array $vues_erreur){
global $rep, $vues;
require($rep.$vues['creationListe']);
$nom=$_POST['nom'];
$model = new ListeModel();
$model->creerListe($nom);
}
public function supprListe(array $vues_erreur){
global $rep, $vues;
require($rep.$vues['suppressionListe']);
$model = new ListeModel();
$model->supprListe();
}
public function creerTache(array $vues_erreur){
global $rep, $vues;
require($rep.$vues['creerTache']);
$intitule = $_POST['intitule'];
$model = new ListeModel();
$model->creerTache();
}
}

@ -44,14 +44,14 @@ class ListeGateway {
return $listes;
}
public function creerTache(int $id, string $intitule, boolean $isCompleted){
public function creerTache(string $intitule){
if(!empty($id) && !empty($intitutle)){
try{
$co = $this->co;
$query = "INSERT INTO Tache VALUES (:id, :intitule, :isCompleted)";
$query = "INSERT INTO Tache VALUES (NULL, :intitule, 0)";
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR), ':intitule' => array($nom, PDO::PARAM_STR), ':isCompleted' => array($taches, PDO::PARAM_STR)));
$co->executeQuery($query, array(':intitule' => array($nom, PDO::PARAM_STR)));
}
catch(PDOException $Exception){
echo 'erreur';
@ -91,6 +91,39 @@ class ListeGateway {
}
}
}
public function creerListe(string $nom, string $idCreateur){
if(!empty($id) && !empty($nom)){
try{
$co = $this->co;
$query = "INSERT INTO Liste VALUES (NULL, :nom)";
$co->executeQuery($query, array(':nom' => array($nom, 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();
}
}
}
}
?>

@ -10,14 +10,14 @@ class UserGateway {
$this->co = $co;
}
public function creerUtilisateur(int $id, string $nom, string $pwd){
public function creerUtilisateur(string $nom, string $pwd){
if(!empty($id) && !empty($nom) && empty($password)){
try{
$co = $this->co;
$query = "INSERT INTO Utilisateur VALUES (:id, :nom, :pwd)";
$query = "INSERT INTO Utilisateur VALUES (NULL, :nom, :pwd)";
$co->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR), ':nom' => array($nom, PDO::PARAM_STR), ':pwd' => array($pwd, PDO::PARAM_STR)));
$co->executeQuery($query, array(':nom' => array($nom, PDO::PARAM_STR), ':pwd' => array($pwd, PDO::PARAM_STR)));
}
catch(PDOException $Excception){
echo 'erreur';
@ -115,38 +115,6 @@ class UserGateway {
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,9 @@
<?php
class UserModel {
}
?>

@ -0,0 +1,48 @@
<?php
class VisiteurModel {
private $gtwUsr;
private $gtwListe;
public function __construct() {
$co = new Connection();
$this->gtwUsr = new UserGateway($co);
$this->gtwListe = new ListeGateway($co);
}
public function get_gtwUsr(): UserGateway {
return $this->gtwUsr;
}
public function get_gtwListe(): ListeGateway {
return $this->gtwListe;
}
public function connexion($login, $mdp){
$results = $this->get_gtwUsr()->getUtilisateurbyNameAndPassword($login, $mdp);
if ($results != NULL){
$_SESSION['role'] = 'user';
$_SESSION['login'] = $login;
return true;
}
return false;
}
public function inscription($login, $mdp){
$this->get_gtwUsr()->creerUtilisateur($login, $mdp);
}
public function creerListe($nom) {
$this->get_gtwListe()->creerListe($nom, NULL);
}
public function supprListe($id) {
$this->get_gtwListe()->delListe($id);
}
public function creerTache(string $intitule){
$this->get_gtwListe()->creerTache($intitule);
}
}
?>

@ -4,13 +4,11 @@ Class Tache {
private int $id;
private string $intitule;
private boolean $isCompleted;
private string $description;
function __construct(int $i, string $in, boolean $is, string $desc){
function __construct(int $i, string $in, boolean $is){
$this->id = $i;
$this->intitule = $in;
$this->isCompleted = $is;
$this->description = $desc;
}
function get_id(): int {
@ -24,10 +22,6 @@ Class Tache {
function get_isCompleted(): boolean {
return $this->isCompleted;
}
function get_description(): string {
return $this->description;
}
}
?>

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

@ -10,9 +10,9 @@
</header>
<div>
<h4>Username</h4>
<input type="text"/>
<input type="text" name="login"/>
<h4>Password</h4>
<input type="password"/>
<input type="password" name="mdp"/>
<br/>
<br/>
<input class="button" type="button" value="Log In"/>

@ -12,9 +12,9 @@
<div>
<p>Please enter all the informations :</p>
<h4>Username</h4>
<input type="text"/>
<input type="text" name="login"/>
<h4>Password</h4>
<input type="password"/>
<input type="password" name="mdp"/>
<h4>Email</h4>
<input type="email"/>
<h4>Date Of Birth</h4>

Loading…
Cancel
Save