diff --git a/business/ListTask.php b/business/ListTask.php index aa34586..5a2ce29 100644 --- a/business/ListTask.php +++ b/business/ListTask.php @@ -1,8 +1,8 @@ owner = $owner; } + function get_id() { return $this->id; } @@ -21,6 +22,14 @@ $this->id = $id; } + function get_nom() { + return $this->nom; + } + + function set_nom($nom) { + $this->nom = $nom; + } + function get_taches() { return $this->taches; } @@ -28,18 +37,11 @@ function set_taches($taches) { $this->taches = $taches; } - - function get_nom() { - return $this->nom; - } - - function set_nom($nom) { - $this->nom= $nom; - } function get_owner() { if($this->owner == "") return NULL; + return $this->owner; } @@ -54,7 +56,5 @@ function set_dc($dc) { $this->dc = $dc; } - - } ?> diff --git a/business/Task.php b/business/Task.php index 5031fcc..d3d85c6 100644 --- a/business/Task.php +++ b/business/Task.php @@ -6,6 +6,7 @@ private $dateDeb; private $dateFin; # $today = date("m.d.y") private string $priorite; + private string $idlist; // # id associating task to list private bool $isDone; // # si la tache est complete diff --git a/business/User.php b/business/User.php index 8f283c2..7de66c5 100644 --- a/business/User.php +++ b/business/User.php @@ -1,13 +1,9 @@ login = $login; - $this->mdp = $mdp; - $this->admin = $admin; } function get_login() { @@ -17,21 +13,5 @@ function set_login($login) { $this->login = $login; } - - function get_mdp() { - return $this->mdp; - } - - function set_mdp($mdp) { - $this->mdp = $mdp; - } - - function get_admin() { - return $this->admin; - } - - function set_admin($admin) { - $this->admin = $admin; - } } ?> \ No newline at end of file diff --git a/config/config.php b/config/config.php index 9e59053..e2a19d3 100644 --- a/config/config.php +++ b/config/config.php @@ -1,6 +1,7 @@ \ No newline at end of file diff --git a/controller/CtrlUser.php b/controller/CtrlUser.php new file mode 100644 index 0000000..0a2359a --- /dev/null +++ b/controller/CtrlUser.php @@ -0,0 +1,39 @@ +Reinit(); + break; + case "validationFormulaire": + $this->ValidationFormulaire($dVueEreur); + break; + //mauvaise action + default: + $dVueEreur[] = "Erreur d'appel php"; + require ($rep.$vues['vuephp1']); + break; + } + } catch (PDOException $e) + { + //si erreur BD, pas le cas ici + $dVueEreur[] = "Erreur inattendue!!! "; + require ($rep.$vues['erreur']); + } + catch (Exception $e2) + { + $dVueEreur[] = "Erreur inattendue!!! "; + require ($rep.$vues['erreur']); + } + exit(0); + } + } + +?> \ No newline at end of file diff --git a/dal/UserGateway.php b/dal/UserGateway.php index 9361d12..d9db4ad 100644 --- a/dal/UserGateway.php +++ b/dal/UserGateway.php @@ -1,20 +1,55 @@ con=$con; - } + public function __construct(Connection $con) { + $this->con = $con; } - public function insert(User $u){ + public function create($login, $mdp){ + $pwrd = password_hash($mdp, PASSWORD_BCRYPT, array("cost" => 12)); + $query = 'INSERT INTO User VALUES (:login, :mdp)'; + $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR), + ':mdp'=>array($pwrd, PDO::PARAM_STR))); + $result = $this->con->getResults(); + return $result; + } - } -} + public function updateLogin($oldValue, $newValue){ + $query = 'UPDATE User SET login = :newValue WHERE login = :oldValue'; + $this->con->executeQuery($query, array(':oldValue'=>array($oldValue, PDO::PARAM_STR), + ':newValue'=>array($newValue, PDO::PARAM_STR))); + } + public function updateMdp($login, $mdp){ + $pwrd = password_hash($mdp, PASSWORD_BCRYPT, array("cost" => 12)); + $query = 'UPDATE User SET mdp = :value WHERE login = :login'; + $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR), + ':value'=>array($pwrd, PDO::PARAM_STR))); + } + public function delete($value){ + $query = 'DELETE FROM User WHERE login = :value'; + $this->con->executeQuery($query, array(':value'=>array($value, PDO::PARAM_STR))); + } + + public function find($value, $parameterkind){ + $query = 'SELECT login FROM User WHERE :parameterkind = :value'; + $this->con->executeQuery($query, array(':value'=>array($value, PDO::PARAM_STR), + ':parameterkind'=>array($parameterkind, PDO::PARAM_STR))); + $result = $this->con->getResults(); + return $result; + } -?> + 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))); + $result = $this->con->getResults(); + return $result; + } + } +?> \ No newline at end of file diff --git a/index.php b/index.php index 3996940..5fe3c7f 100644 --- a/index.php +++ b/index.php @@ -1,8 +1,8 @@ 2do index

"; + $fc = new FrontCtrl(); + $TMessage = array(); + + require_once(controller/FrontCtrl.php); + require(erreur.php); ?> + diff --git a/model/UserModel.php b/model/UserModel.php index 39b0a7a..5ed7c9a 100644 --- a/model/UserModel.php +++ b/model/UserModel.php @@ -1,4 +1,63 @@ + require('../business/User.php'); + class UserModel{ + private $con; + private $gat; + + public function __construct(Connection $con) { + $this->con = $con; + $this->gat = new GatUser($con); } + + function connexion($login, $mdp){ + $gat->findUser($login, $mdp); + $_SESSION['login'] = $login; + } + + function deconnexion(){ + session_unset(); + session_destroy(); + $_SESSION = array(); + } + + function isConnected($login){ //teste rôle dans la session, retourne instance d’objet ou booleen + if (isset($_SESSION['login'])) + { + return true; + } + else return false; + } + + function ajouter($login, $mdp){ + $user = $this->findByLogin($login); + if (empty($user)) + $this->gat->create($login, $mdp); + } + + function supprimer($login){ + $this->gat->delete($login); + } + + function modifMdp($login, $mdp){ + $this->gat->updateMdp($login, $mdp); + } + + function findByLogin($login){ + $user = null; + if ($login !== " " && $login != null ) + { + $results = $this->gat->find($login, 'login'); + foreach($results as $row){ + $user = new User($results['login']); + } + return $user; + } + } + + function modifLogin($oldLogin, $newLogin){ + $user = $this->findByLogin($oldLogin); + if (empty($user)) + $this->gat->updateLogin($oldLogin, $newLogin); + } + } + +?> \ No newline at end of file diff --git a/tests/test.php b/tests/test.php index 1fef62d..a55aa07 100644 --- a/tests/test.php +++ b/tests/test.php @@ -35,3 +35,30 @@ foreach($tasks as $i) $mt->addList('002','todo2','nifranco'); $mt->modifList('2','nom','22do'); //mt->supList('2'); + +/* ------------- +TEST ANNA +----------------*/ + +require('../dal/UserGateway.php'); +require('../model/UserModel.php'); + +// Test Gateway User + +// $gat = new UserGateway($con); +// $gat->create('Nicolas', 'tranquilloubilou'); +// $gat->updateLogin('Nicolas', 'RicharlisonR9'); +// $gat->updateMdp('RicharlisonR9', 'hexachampion'); +// $tab = $gat->find('RicharlisonR9', 'login'); +// $gat->delete('RicharlisonR9'); + +// Test Modèle User + +// $mdl = new UserModel($con); +// $mdl->ajouter('Anna', 'unmdptrescomplique'); +// $mdl->modifLogin('Anna', 'Aeryn'); +// $mdl->modifMdp('Aeryn', 'wtfmec'); +// $mdl->supprimer('Aeryn'); + +?> +