fixed merge conflicts with user branch

list-Gtw-Mdl
Nicolas FRANCO 2 years ago
commit 30f4fa92c9

@ -1,8 +1,8 @@
<?php <?php
class ListTask{ class ListTask{
private int $id; private int $id;
private array $taches;
private string $nom; private string $nom;
private array $taches;
private string $owner; private string $owner;
private int $dc; // done counter private int $dc; // done counter
@ -13,6 +13,7 @@
$this->owner = $owner; $this->owner = $owner;
} }
function get_id() { function get_id() {
return $this->id; return $this->id;
} }
@ -21,25 +22,26 @@
$this->id = $id; $this->id = $id;
} }
function get_taches() { function get_nom() {
return $this->taches; return $this->nom;
} }
function set_taches($taches) { function set_nom($nom) {
$this->taches = $taches; $this->nom = $nom;
} }
function get_nom() { function get_taches() {
return $this->nom; return $this->taches;
} }
function set_nom($nom) { function set_taches($taches) {
$this->nom= $nom; $this->taches = $taches;
} }
function get_owner() { function get_owner() {
if($this->owner == "") if($this->owner == "")
return NULL; return NULL;
return $this->owner; return $this->owner;
} }
@ -54,7 +56,5 @@
function set_dc($dc) { function set_dc($dc) {
$this->dc = $dc; $this->dc = $dc;
} }
} }
?> ?>

@ -6,6 +6,7 @@
private $dateDeb; private $dateDeb;
private $dateFin; # $today = date("m.d.y") private $dateFin; # $today = date("m.d.y")
private string $priorite; private string $priorite;
private string $idlist; // # id associating task to list private string $idlist; // # id associating task to list
private bool $isDone; // # si la tache est complete private bool $isDone; // # si la tache est complete

@ -1,13 +1,9 @@
<?php <?php
class User{ class User{
private string $login; private string $login;
private string $mdp;
private bool $admin;
function __construct($login, $mdp, $admin=False) { function __construct($login) {
$this->login = $login; $this->login = $login;
$this->mdp = $mdp;
$this->admin = $admin;
} }
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_admin() {
return $this->admin;
}
function set_admin($admin) {
$this->admin = $admin;
}
} }
?> ?>

@ -1,6 +1,7 @@
<?php <?php
//gen
$rep=__DIR__.'/../';
//gen require('dal/Connection.php');
$rep=__DIR__.'/../'; $con = new Connection('mysql:host=localhost;dbname=dbanboudoul', 'anboudoul', 'achanger');
?> ?>

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

@ -1,20 +1,55 @@
<?php <?php
require_once("Conncetion.php");
include_once("../business/Task.php");
class UserGateway // password_hash
{ // password_verify
public Connection $con; class UserGateway{
private $con;
public function __construct(Connection $con){ public function __construct(Connection $con) {
$this->con=$con; $this->con = $con; }
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 insert(User $u){ 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;
}
}
?> ?>

@ -1,8 +1,8 @@
<?php <?php
# $fc = new FrontCtrl(); $fc = new FrontCtrl();
# $TMessage = array(); $TMessage = array();
#
# require_once(controller/FrontCtrl.php); require_once(controller/FrontCtrl.php);
# require(erreur.php); require(erreur.php);
echo "<h1>2do index<h1>";
?> ?>

@ -1,4 +1,63 @@
<?php <?php
#finduserbylogin require('../business/User.php');
#recup infos de la gateway et transforme en instance de classe metier 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 dobjet 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);
}
}
?> ?>

@ -35,3 +35,30 @@ foreach($tasks as $i)
$mt->addList('002','todo2','nifranco'); $mt->addList('002','todo2','nifranco');
$mt->modifList('2','nom','22do'); $mt->modifList('2','nom','22do');
//mt->supList('2'); //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');
?>

Loading…
Cancel
Save