Test Gateway et controlleur user

user
Anna BOUDOUL 2 years ago
parent 3d9eb1c237
commit 599e30def6

@ -1,11 +1,13 @@
<?php <?php
class ListTask{ class ListTask{
private int $id; private int $id;
private string $nom;
private array $taches; private array $taches;
function __construct($id, $taches) { function __construct($id, $taches, $owner) {
$this->id = $id; $this->id = $id;
$this->taches = $taches; $this->taches = $taches;
$this->owner = $owner;
} }
function get_id() { function get_id() {
@ -16,6 +18,14 @@
$this->id = $id; $this->id = $id;
} }
function get_nom() {
return $this->nom;
}
function set_nom($nom) {
$this->nom = $nom;
}
function get_taches() { function get_taches() {
return $this->taches; return $this->taches;
} }
@ -23,5 +33,13 @@
function set_taches($taches) { function set_taches($taches) {
$this->taches = $taches; $this->taches = $taches;
} }
function get_owner() {
return $this->owner;
}
function set_owner($owner) {
$this->owner = $owner;
}
} }
?> ?>

@ -1,13 +1,9 @@
<?php <?php
class User{ class User{
private int $id;
private string $login; private string $login;
private string $mdp;
function __construct($id, $login, $mdp) { function __construct($login) {
$this->id = $id;
$this->login = $login; $this->login = $login;
$this->mdp = $mdp;
} }
function get_login() { function get_login() {
@ -17,21 +13,5 @@
function set_login($login) { function set_login($login) {
$this->login = $login; $this->login = $login;
} }
function get_mdp() {
return $this->mdp;
}
function set_mdp($mdp) {
$this->mdp = $mdp;
}
function get_id() {
return $this->id;
}
function set_id($id) {
$this->id = $id;
}
} }
?> ?>

@ -0,0 +1,39 @@
<?php
class CtrlUser{
function __construct(){
global $vues;
$rep=__DIR__.'/../';
$dVueEreur = array ();
try{
$action=$_REQUEST['action'];
switch($action) {
case NULL:
$this->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);
}
}
?>

@ -13,19 +13,20 @@
$query = 'INSERT INTO User VALUES (:login, :mdp)'; $query = 'INSERT INTO User VALUES (:login, :mdp)';
$this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR), $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR),
':mdp'=>array($pwrd, PDO::PARAM_STR))); ':mdp'=>array($pwrd, PDO::PARAM_STR)));
$result = $con->getResults(); $result = $this->con->getResults();
return $result; return $result;
} }
public function updateLogin($value){ public function updateLogin($oldValue, $newValue){
$query = 'UPDATE User WHERE login = :value'; $query = 'UPDATE User SET login = :newValue WHERE login = :oldValue';
$this->con->executeQuery($query, array(':value'=>array($value, PDO::PARAM_STR))); $this->con->executeQuery($query, array(':oldValue'=>array($oldValue, PDO::PARAM_STR),
':newValue'=>array($newValue, PDO::PARAM_STR)));
} }
public function updateMdp($login, $mdp){ public function updateMdp($login, $mdp){
$pwrd = password_hash($mdp, PASSWORD_BCRYPT, array("cost" => 12)); $pwrd = password_hash($mdp, PASSWORD_BCRYPT, array("cost" => 12));
$query = 'UPDATE User SET mdp = :value WHERE login = :login'; $query = 'UPDATE User SET mdp = :value WHERE login = :login';
$this->con->executeQuery($query, array(':login'=>array($pwrd, PDO::PARAM_STR), $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR),
':value'=>array($pwrd, PDO::PARAM_STR))); ':value'=>array($pwrd, PDO::PARAM_STR)));
} }
@ -41,5 +42,14 @@
$result = $this->con->getResults(); $result = $this->con->getResults();
return $result; 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;
}
} }
?> ?>

@ -1,4 +1,5 @@
<?php <?php
require('../business/User.php');
class ModelUser{ class ModelUser{
private $con; private $con;
private $gat; private $gat;
@ -7,32 +8,56 @@
$this->con = $con; $this->con = $con;
$this->gat = new GatUser($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 dobjet ou booleen
if (isset($_SESSION['login']))
{
return true;
}
else return false;
}
function ajouter($login, $mdp){ function ajouter($login, $mdp){
$user = findByLogin($login); $user = $this->findByLogin($login);
if (empty($user)) if (empty($user))
$gat->create($login, $mdp); $this->gat->create($login, $mdp);
} }
function supprimer($login){ function supprimer($login){
$gat->delete($login); $this->gat->delete($login);
} }
function modifMdp($login, $mdp){ function modifMdp($login, $mdp){
$gat->updateMdp($login, $mdp); $this->gat->updateMdp($login, $mdp);
}
function modifLogin($login){
$user = findByLogin($login);
if (empty($user))
$gat->updateLogin($login);
} }
function findByLogin($login){ function findByLogin($login){
$user = null;
if ($login !== " " && $login != null ) if ($login !== " " && $login != null )
$results = $gat->find($login, "login"); {
$user = new User($results["login"]); $results = $this->gat->find($login, 'login');
foreach($results as $row){
$user = new User($results['login']);
}
return $user; return $user;
} }
} }
function modifLogin($oldLogin, $newLogin){
$user = $this->findByLogin($oldLogin);
if (empty($user))
$this->gat->updateLogin($oldLogin, $newLogin);
}
}
?> ?>

@ -1,7 +1,24 @@
<?php <?php
require('../dal/Connection.php'); require('../dal/Connection.php');
require('../dal/GatUser.php'); require('../dal/GatUser.php');
require('../model/ModelUser.php');
$con = new Connection('mysql:host=localhost;dbname=dbanboudoul', 'anboudoul', 'achanger'); $con = new Connection('mysql:host=localhost;dbname=dbanboudoul', 'anboudoul', 'achanger');
$gat = new GatUser($con);
$gat->create("Nicolas", "tranquiloubilou"); // Test Gateway User
// $gat = new GatUser($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 ModelUser($con);
// $mdl->ajouter('Anna', 'unmdptrescomplique');
// $mdl->modifLogin('Anna', 'Aeryn');
// $mdl->modifMdp('Aeryn', 'wtfmec');
// $mdl->supprimer('Aeryn');
?> ?>
Loading…
Cancel
Save