merge with userctrl

userctrl
Nicolas FRANCO 2 years ago
commit b501e081f2

@ -11,6 +11,7 @@
$this->nom = $nom;
$this->taches = [];
$this->owner = $owner;
$this->dc = $dc;
}

@ -6,10 +6,9 @@ class FrontController
//private UserModel $ursMdl;
//private $action_User;
function __construct($ursMdl=new UserModel(), $action_User=[]){
$this->$ursMdl = $ursMdl;
$this->$action_User = $action_User;
function __construct(){
session_start();
$ursMdl = new UserModel();
try{
$user = $this->usrMdl.isUser(); // cette fonction retourne quoi?
@ -20,20 +19,17 @@ class FrontController
# appel controlleur visiteur avec action connecter
require("VisitCtrl.php");
$visitCtrl = new VisitCtrl();
$visitCtrl.handleAction('connecter');
// inclure la vue de connexion
$visitCtrl->goconnexion();
} else { # sinon
# handle action avec controlleur user
require("UserCtrl.php");
$userCtrl = new UserCtrl(); //action ici
$userCtrl.handleAction($action);
$userCtrl = new UserCtrl();
}
} else { # sinon forcement action visiteur
# appel controlleur visiteur avec l'action
require("VisitCtrl.php");
$visitCtrl = new VisitCtrl();
$visitCtrl.handleAction($action);
}
} catch (Exception $e){ // verifier si catch bon
require("../view/erreur.php");

@ -1,56 +1,45 @@
<?php
class CtrlUser
class UserCtrl
{
private $model;
private $view;
private $con;
public function __construct(TaskModel $model, HomeView $view,
Connection $con){
session_start();
$this->model = $model;
$this->view = $view;
public function __construct(Connection $con){
$this->con = $con;
}
public function handleAction(){
$this->model = new UserModel($this->con);
try{
$action=$_REQUEST['action'];
switch($action){
// pas d'action afficher la home page avec toutes les listes
case NULL:
$this->home();
break;
// ajouter une liste publique
case 'creer_liste_pub':
$this->newList('private');
// voir les listes privees
case 'voir_liste_priv':
$this->loadListePriv();
break;
// ajouter une liste privee
case 'creer_liste_priv':
$this->newList('public');
break;
// supprimer une liste
case 'supprimer_liste':
$this->delList();
break;
// changer nom de la liste
case 'changer_nom':
$this->changeListName();
$this->newListPrivate();
break;
// ajouter une tache
// completer tache
}
} catch(Exception $e) {
require("../view/erreur.php");
}
}
public function loadListePriv(){
$name = "Liste privée";
$TabList = array();
// $TabList[] = new ListTask(0, "Projet PHP");
// $TabList[] = new ListTask(1, "Projet Blazor");
$TabListPriv = $this->model->getPrivateList();
require("../view/liste.php");
}
public function newListPrivate(){
$nom=$_POST['listeNom'];
insertL(new ListTask(0, $nom, $_SESSION['login']));
}
}
?>

@ -69,6 +69,7 @@ class VisitCtrl
# dans vue check if isset
# display content
$public_lists = $this->taskModel.loadPublicList();
require("../view/home.php");
}
function go_connection(){

@ -44,12 +44,11 @@
}
public function findUser($login, $mdp){
$pwrd = password_hash($mdp, PASSWORD_BCRYPT, array("cost" => 12));
$query = 'SELECT login FROM User WHERE login = :login AND mdp = :mdp';
$this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR),
':mdp'=>array($pwrd, PDO::PARAM_STR)));
$query = 'SELECT mdp FROM User WHERE login = :login';
$this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR)));
$result = $this->con->getResults();
return $result;
if(password_verify($mdp, $result[0]['mdp']))
return $login;
}
}
?>

@ -66,7 +66,6 @@ class TaskModel
$row = $this->gtw->findListTask($row);
}
return $lists;
}
function loadPrivateLists($user){

@ -6,11 +6,16 @@
public function __construct(Connection $con) {
$this->con = $con;
$this->gat = new GatUser($con); }
$this->gat = new UserGateway($con);
}
function connexion($login, $mdp){
$gat->findUser($login, $mdp);
$_SESSION['login'] = $login;
$result = $this->gat->findUser($login, $mdp);
if (isset($result))
{
$_SESSION['login'] = $result;
}
echo $_SESSION['login'];
}
function deconnexion(){
@ -20,7 +25,7 @@
}
function isConnected($login){ //teste rôle dans la session, retourne instance dobjet ou booleen
if (isset($_SESSION['login']))
if ($_SESSION['login'])
{
return true;
}

@ -11,10 +11,10 @@ echo "<h1>2do test</h1>";
# connection
include("credentials.php");
$con = new Connection('mysql:host=localhost;dbname=phpproject',$user,$pass);
$con = new Connection('mysql:host=localhost;dbname=dbanboudoul', 'anboudoul', 'achanger');
# gateway
$tgt = new TaskGateway($con);
// $tgt = new TaskGateway($con);
//$tgt->insert($t);
//$tgt->delete('10');
//$taches = $tgt->findUserList('nifranco');
@ -49,6 +49,7 @@ TEST ANNA
require('../dal/UserGateway.php');
require('../model/UserModel.php');
require('../controller/UserCtrl.php');
// Test Gateway User

@ -0,0 +1,14 @@
<?php
echo '<head>
<meta charset="utf-8" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous">
</head>';
echo '<h1>'.$name.'</h1><center>';
echo '<div class="list-group list-group-light">';
foreach($TabList as $liste){
echo '<button type="button" class="list-group-item list-group-item-action px-3 border-0">'.$liste->get_nom().'</button>';
}
echo '</div></center>';
?>
Loading…
Cancel
Save