diff --git a/automate.php b/automate.php index a0c84ef..9341a9f 100755 --- a/automate.php +++ b/automate.php @@ -1,13 +1,7 @@ \ No newline at end of file diff --git a/config/repositories.json b/config/repositories.json index 02c919b..5be92f0 100755 --- a/config/repositories.json +++ b/config/repositories.json @@ -2,25 +2,34 @@ "user" :[ "create", + "getAll", "getById", "getByCode", - "getAll", - "getGroup", + "getByUsername", + + "getGroups", "delete" ], "machine" :[ - "get", + "create", + "getAll", + "getById", + "getGroup" ], "group" :[ - "get", + "create", + "link", + "unlink", + "getAll", - "getUser", - "getMachine" + "getById", + + "getMembers" ] } \ No newline at end of file diff --git a/index.php b/index.php index 2138ed7..4572487 100755 --- a/index.php +++ b/index.php @@ -1,7 +1,11 @@ get('settings/', function(){ include __ROOT__.'/view.php'; }); // Dispatcher - $R->get('f(?:/([\w-]+))*/?', function(){ new \manager\ResourceDispatcher($_GET['url'], true); }); + $R->get('f(?:/([\w-]+))*/?', function(){ new ResourceDispatcher($_GET['url'], true); }); // Api $R->post('api/?', function(){ - $request = \manager\ModuleRequest::fromPost($_POST); + $request = ModuleRequest::fromPost($_POST); $answer = $request->dispatch(); echo $answer->serialize(); diff --git a/manager/Database.php b/manager/Database.php index 6f285a2..17a1fcc 100755 --- a/manager/Database.php +++ b/manager/Database.php @@ -1,6 +1,8 @@ host.';dbname='.$this->dbname, $this->username, $this->password); // On signale que tout s'est bien passe - self::$error = \manager\ManagerError::Success; + self::$error = ManagerError::Success; }catch(Exception $e){ // On signale qu'il y a une erreur - self::$error = \manager\ManagerError::PDOConnection; + self::$error = ManagerError::PDOConnection; } } /* retourne une instance de la classe */ public static function getInstance(){ - if( self::$instance == null || self::$error != \manager\ManagerError::Success ){ // Si aucune instance existante OU erreur de connection + if( self::$instance == null || self::$error != ManagerError::Success ){ // Si aucune instance existante OU erreur de connection // chargement de la configuration du server SQL if( !isset($_SERVER['HTTP_HOST']) || isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'stefproject' ) diff --git a/manager/ModuleAnswer.php b/manager/ModuleAnswer.php index 808a4b3..493f95b 100755 --- a/manager/ModuleAnswer.php +++ b/manager/ModuleAnswer.php @@ -1,6 +1,7 @@ Tableau contenant le nom des classes + * + */ + function autoload($classes){ + foreach($classes as $class){ + $name_only = substr(strrchr($class, '\\'), 1); + var_dump('use '.$class.' as '.$name_only.';'); + eval('use '.$class.' as '.$name_only.';'); + } + } + + + + + + + + /* AUTOLOADER * @@ -30,9 +58,10 @@ $path = str_replace('\\', '/', $className) . '.php'; $path = __ROOT__.'/'.$path; - // Si le fichier existe, on l'inclut + // Si le fichier existe if( file_exists($path) ) - require_once $path; + require_once $path; // on inclue le fichier + } // On definit l'autoloader comme autoloader (obvious) diff --git a/manager/module/userDefault.php b/manager/module/userDefault.php index db5885d..f1a7342 100755 --- a/manager/module/userDefault.php +++ b/manager/module/userDefault.php @@ -1,6 +1,10 @@ $users->answer() @@ -37,54 +41,62 @@ public static function create($code=null, $username=null, $firstname=null, $lastname=null, $mail=null, $password=null, $status=null){ /* [1] Normalisation + verification des donnees =========================================================*/ - $password_hash = \manager\sessionManager::secure_sha1($password); + $password_hash = sessionManager::secure_sha1($password); - $correct_param = \manager\Database::check('user.code', $code); - $correct_param = $correct_param && \manager\Database::check('user.username', $username); - $correct_param = $correct_param && \manager\Database::check('user.firstname', $firstname); - $correct_param = $correct_param && \manager\Database::check('user.lastname', $lastname); - $correct_param = $correct_param && \manager\Database::check('user.mail', $mail); - $correct_param = $correct_param && \manager\Database::check('user.password', $password_hash); - $correct_param = $correct_param && \manager\Database::check('user.status', $status); + $correct_param = Database::check('user.code', $code); + $correct_param = $correct_param && Database::check('user.username', $username); + $correct_param = $correct_param && Database::check('user.firstname', $firstname); + $correct_param = $correct_param && Database::check('user.lastname', $lastname); + $correct_param = $correct_param && Database::check('user.mail', $mail); + $correct_param = $correct_param && Database::check('user.password', $password_hash); + $correct_param = $correct_param && Database::check('user.status', $status); // Si les parametres ne sont pas corrects, on retourne une erreur if( !$correct_param ) - return array('ModuleError' => \manager\ManagerError::ParamError); + return array('ModuleError' => ManagerError::ParamError); + + /* [2] Creation de l'utilisateur =========================================================*/ - $create_user = new \manager\Repo('user/create', array($code, $username, $firstname, $lastname, $mail, $password_hash, $status) ); + $create_user = new Repo('user/create', array($code, $username, $firstname, $lastname, $mail, $password_hash, $status) ); $id_user = $create_user->answer(); // Si une erreur est retournee, on retourne une erreur if( $id_user === false ) - return array('ModuleError' => \manager\ManagerError::ModuleError); + return array('ModuleError' => ManagerError::ModuleError); + + /* [3] Creation du groupe de meme nom que l'username =========================================================*/ - $create_group = new \manager\Repo('group/create', array($username) ); + $create_group = new Repo('group/create', array($username) ); $id_group = $create_group->answer(); // Si une erreur est retournee, on retourne une erreur if( $id_group === false ) - return array('ModuleError' => \manager\ManagerError::ModuleError); + return array('ModuleError' => ManagerError::ModuleError); + + /* [4] Association au groupe =========================================================*/ - $assoc_goup = new \manager\Repo('group/associate', array($id_user, $id_group)); + $assoc_goup = new Repo('group/link', array($id_user, $id_group)); $id_assoc = $assoc_goup->answer(); // Si une erreur est retournee, on retourne une erreur if( $id_assoc === false ) - return array('ModuleError' => \manager\ManagerError::ModuleError); + return array('ModuleError' => ManagerError::ModuleError); + + /* [5] Gestion du retour =========================================================*/ return array( - 'ModuleError' => \manager\ManagerError::Success, + 'ModuleError' => ManagerError::Success, 'id_user' => $id_user ); } diff --git a/manager/repo/user.php b/manager/repo/user.php index 926dacb..52b731d 100755 --- a/manager/repo/user.php +++ b/manager/repo/user.php @@ -1,9 +1,38 @@ Code RFID de l'utilisateur + * @username Identifiant l'utilisateur + * @firstname Prenom de l'utilisateur + * @lastcode Nom de l'utilisateur + * @mail Adresse email de l'utilisateur + * @password Mot de passe de l'utilisateur + * @status Status de l'utilisateur + * + * @return nomRetour Description du retour + * + */ + public static function create($code, $username, $firstname, $lastname, $mail, $password, $status){ + /* [1] Creation de l'utilisateur (unicite de l'username) + =========================================================*/ + $check_unique = ( self::getByCode($code) == false ); + $check_unique = $check_unique && ( self::getByUsername($username) == false ); + + var_dump($check_unique); + + } + + + + + + /* RENVOIE LA LISTE DE TOUS LES UTILISATEURS * @@ -12,13 +41,13 @@ */ public static function getAll(){ // On ecrit la requete - $request = \manager\Database::getPDO()->query("SELECT * FROM user ORDER BY id_user"); + $request = Database::getPDO()->query("SELECT * FROM user ORDER BY id_user"); // On recupere le resutat $answer = $request->fetchAll(); // On retourne en supprimant les indices numeriques - return \manager\Database::delNumeric( $answer ); + return Database::delNumeric( $answer ); } @@ -28,11 +57,6 @@ - - - - - /* RENVOIE L'UTILISATEUR D'ID DONNE * * @id Id de l'utilisateur en question @@ -43,7 +67,7 @@ */ public static function getById($id){ // On ecrit la requete - $request = \manager\Database::getPDO()->prepare("SELECT * FROM user + $request = Database::getPDO()->prepare("SELECT * FROM user WHERE id_user = :id"); // On execute la requete @@ -59,7 +83,7 @@ return false; // On retourne en supprimant les indices numeriques - return \manager\Database::delNumeric( $answer, true ); + return Database::delNumeric( $answer, true ); } @@ -69,11 +93,6 @@ - - - - - /* RENVOIE L'UTILISATEUR DE CODE DONNE * * @code Code de l'utilisateur en question @@ -84,7 +103,7 @@ */ public static function getByCode($code){ // On ecrit la requete - $request = \manager\Database::getPDO()->prepare("SELECT * FROM user + $request = Database::getPDO()->prepare("SELECT * FROM user WHERE code = :code"); // On execute la requete @@ -100,7 +119,9 @@ return false; // On retourne en supprimant les indices numeriques - return \manager\Database::delNumeric( $answer, true ); + return Database::delNumeric( $answer, true ); + + } @@ -110,31 +131,104 @@ - /* CREATION D'UN UTILISATEUR ET DE SON GROUPE INDIVIDUEL + /* RENVOIE L'UTILISATEUR D'USERNAME DONNE * - * @code Code RFID de l'utilisateur - * @username Identifiant l'utilisateur - * @firstname Prenom de l'utilisateur - * @lastcode Nom de l'utilisateur - * @mail Adresse email de l'utilisateur - * @password Mot de passe de l'utilisateur - * @status Status de l'utilisateur + * @username Identifiant de l'utilisateur en question * - * @return nomRetour Description du retour + * @return utilisateur Renvoie l'utilisateur d'username donne si existe + * @return error Retourne FALSE si aucun resultat * */ - public static function create($code, $username, $firstname, $lastname, $mail, $password, $status){ - /* [1] Creation de l'utilisateur (unicite de l'username) - =========================================================*/ - $check_unique = ( self::getByCode($code) == false ); + public static function getByUsername($username){ + // On ecrit la requete + $request = Database::getPDO()->prepare("SELECT * FROM user + WHERE username = :username"); - var_dump($check_unique); + // On execute la requete + $request->execute(array( + ':username' => $username + )); + // On recupere 1 seul utilisateur + $answer = $request->fetch(); + + // Gestion d'erreur -> aucun resultat + if( $answer == null ) + return false; + + // On retourne en supprimant les indices numeriques + return Database::delNumeric( $answer, true ); } + + + + + /* RENVOIE LES GROUPE AUQUELS UN UTILISATEUR DONNE APPARTIENT + * + * @id_user UID de l'utilisateur en question + * + * @return groups Renvoie un tableau d'UID des groupes + * + */ + public static function getGroups($id_user){ + /* [1] On redige/execute la requete + =========================================================*/ + $select_groups = Database::getPDO()->prepare("SELECT gm.id_group FROM user as u, group_merge as gm + WHERE u.id_user = gm.id_user + AND u.id_user = :id_user + ORDER BY gm.id_user ASC"); + $select_groups->execute(array( + ':id_user' => $id_user + )); + + // On retourne en supprimant les indices numeriques + return Database::delNumeric( $select_groups->fetchAll() ); + } + + + + + + + + + /* SUPPRIME UN UTILISATEUR DONNE + * + * @id_user UID de l'utilisateur en question + * + * @return status Retourne si oui ou non l'utilisateur a bien ete supprime + * + */ + public static function delete($id_user){ + /* [1] On redige/execute la requete + =========================================================*/ + $delete_user = Database::getPDO()->prepare("DELETE FROM user WHERE id_user = :id_user"); + $delete_user->execute(array( + ':id_user' => $id_user + )); + + + /* [2] On verifie que l'utilisateur n'existe plus + =========================================================*/ + return ( self::getById($id_user) === false ); + } + + + + + + + + + + + + + } diff --git a/phpunit/coverage/Database.php.html b/phpunit/coverage/Database.php.html index c33edbe..ad7ab6f 100755 --- a/phpunit/coverage/Database.php.html +++ b/phpunit/coverage/Database.php.html @@ -431,7 +431,7 @@ Dead Code

- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 18:08:46 CET 2016.

diff --git a/phpunit/coverage/ManagerError.php.html b/phpunit/coverage/ManagerError.php.html index 6c9d4f8..6b44be9 100644 --- a/phpunit/coverage/ManagerError.php.html +++ b/phpunit/coverage/ManagerError.php.html @@ -220,7 +220,7 @@ Dead Code

- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 18:08:46 CET 2016.

diff --git a/phpunit/coverage/ResourceDispatcher.php.html b/phpunit/coverage/ResourceDispatcher.php.html index 3272a19..04a862e 100644 --- a/phpunit/coverage/ResourceDispatcher.php.html +++ b/phpunit/coverage/ResourceDispatcher.php.html @@ -450,7 +450,7 @@ Dead Code

- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 18:08:46 CET 2016.

diff --git a/phpunit/coverage/autoloader.php.html b/phpunit/coverage/autoloader.php.html index e37027e..32d8aab 100755 --- a/phpunit/coverage/autoloader.php.html +++ b/phpunit/coverage/autoloader.php.html @@ -153,7 +153,7 @@ Dead Code

- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 18:08:46 CET 2016.

diff --git a/phpunit/coverage/index.dashboard.html b/phpunit/coverage/index.dashboard.html index a522a3d..d1e14ba 100755 --- a/phpunit/coverage/index.dashboard.html +++ b/phpunit/coverage/index.dashboard.html @@ -59,7 +59,7 @@ diff --git a/phpunit/coverage/index.html b/phpunit/coverage/index.html index ce19264..92f8c53 100755 --- a/phpunit/coverage/index.html +++ b/phpunit/coverage/index.html @@ -177,7 +177,7 @@ High: 70% to 100%

- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 18:08:46 CET 2016.

diff --git a/phpunit/coverage/sessionManager.php.html b/phpunit/coverage/sessionManager.php.html index cb2a80b..c52bd9d 100644 --- a/phpunit/coverage/sessionManager.php.html +++ b/phpunit/coverage/sessionManager.php.html @@ -284,7 +284,7 @@ Dead Code

- Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 17:24:32 CET 2016. + Generated by PHP_CodeCoverage 1.2.13 using PHP 5.5.9-1ubuntu4.14 and PHPUnit 3.7.28 at Sat Feb 13 18:08:46 CET 2016.

diff --git a/todo.md b/todo.md index 835a672..35a99aa 100755 --- a/todo.md +++ b/todo.md @@ -39,6 +39,7 @@ ######## # FAIT # ######## +- [x] Ajout de "use CLASS;" dans les fichiers pour simplifier la lisibilite - [x] [phpunit/sessionManager] test unitaires du manager de session php - [x] [ModuleAnswer] Gestion des erreurs au niveau interne des Modules - [x] [autoloader][phpunit/bootstrap.php] Correction des bugs de $_SERVER avec PHPUnit -> autoloader + bootstrap personnalise