2016-04-12 12:27:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\module;
|
|
|
|
use \manager\sessionManager;
|
|
|
|
use \manager\Database;
|
|
|
|
use \manager\ManagerError;
|
|
|
|
use \manager\Repo;
|
|
|
|
|
2016-04-14 10:45:54 +00:00
|
|
|
class user{
|
2016-04-12 12:27:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* VERIFICATION DES LOGINS D'UN UTILISATEUR
|
|
|
|
*
|
|
|
|
* @login<String> Username ou adresse mail de l'utilisateur
|
|
|
|
* @password<String> Password de l'utilisateur
|
|
|
|
*
|
|
|
|
* @return id_user<int> Retourne l'id de l'utilisateur si les logins sont corrects
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function login($login, $password){
|
|
|
|
/* [1] On verifie les logins
|
|
|
|
=========================================================*/
|
2016-04-14 10:45:54 +00:00
|
|
|
$check = new Repo('user/login', array($login, $password));
|
2016-04-12 14:30:14 +00:00
|
|
|
$user = $check->answer();
|
2016-04-12 12:27:54 +00:00
|
|
|
|
|
|
|
// Si le login/password est incorrect, on retourne une erreur
|
2016-04-12 14:30:14 +00:00
|
|
|
if( $user === false ) return array('ModuleError' => ManagerError::ModuleError);
|
2016-04-12 12:27:54 +00:00
|
|
|
|
|
|
|
|
2016-04-12 14:30:14 +00:00
|
|
|
/* [2] Gestion du login
|
2016-04-12 12:27:54 +00:00
|
|
|
=========================================================*/
|
2016-04-12 14:30:14 +00:00
|
|
|
$_SESSION['userid'] = $user['id_user'];
|
|
|
|
$_SESSION['username'] = $user['login'];
|
|
|
|
$_SESSION['permission'] = explode( ',', str_replace(' ', '', $user['permission']) );
|
|
|
|
|
|
|
|
/* [4] Retour de l'id user
|
|
|
|
=========================================================*/
|
|
|
|
|
2016-04-12 12:27:54 +00:00
|
|
|
return array(
|
|
|
|
'ModuleError' => ManagerError::Success,
|
2016-04-12 14:30:14 +00:00
|
|
|
'id_user' => $user['id_user']
|
2016-04-12 12:27:54 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2016-04-12 14:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* DECONNEXION D'UN UTILISATEUR
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function logout(){
|
|
|
|
$_SESSION['userid'] = null;
|
|
|
|
$_SESSION['username'] = null;
|
|
|
|
$_SESSION['permission'] = array();
|
|
|
|
}
|
|
|
|
|
2016-04-14 10:45:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* RETOURNE L'UTILISATEUR D'ID DONNE
|
|
|
|
*
|
|
|
|
* @id_user<int> UID de l'utilisateur en question
|
|
|
|
*
|
|
|
|
* @return user<Array> Tableau contenant les informations de l'utilisateur
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getById($user_id){
|
|
|
|
/* [1] On recupere les donnees de l'utilisateur
|
|
|
|
=========================================================*/
|
|
|
|
$getUser = new Repo('user/getById', array($user_id));
|
|
|
|
$user_data = $getUser->answer();
|
|
|
|
|
|
|
|
// Si aucun utilisateur n'est trouve
|
|
|
|
if( $user_data === false ) return array('ModuleError' => ManagerError::ModuleError);
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] On met les permissions au bon format (string -> array)
|
|
|
|
=========================================================*/
|
|
|
|
$user_data['permission'] = explode( ',', str_replace(' ', '', $user_data['permission']) );
|
|
|
|
|
|
|
|
/* [3] Gestion du retour
|
|
|
|
=========================================================*/
|
|
|
|
return array(
|
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'user' => $user_data
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-12 12:27:54 +00:00
|
|
|
// [x] "login",
|
2016-04-12 14:47:06 +00:00
|
|
|
// [x] "logout",
|
2016-04-14 10:45:54 +00:00
|
|
|
// [x] "getById",
|
2016-04-12 12:27:54 +00:00
|
|
|
// [ ] "getAll",
|
|
|
|
|
|
|
|
// [ ] "create",
|
|
|
|
// [ ] "remove",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|