2016-04-12 12:27:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\module;
|
|
|
|
use \manager\sessionManager;
|
|
|
|
use \manager\Database;
|
|
|
|
use \manager\ManagerError;
|
|
|
|
use \manager\Repo;
|
|
|
|
|
|
|
|
class users{
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
=========================================================*/
|
|
|
|
$check = new Repo('users/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
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
// [x] "login",
|
|
|
|
// [ ] "getById",
|
|
|
|
// [ ] "getAll",
|
|
|
|
|
|
|
|
// [ ] "create",
|
|
|
|
// [ ] "edit",
|
|
|
|
// [ ] "remove",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|