71 lines
3.4 KiB
PHP
71 lines
3.4 KiB
PHP
<?php require('manager/security.php'); session_init();
|
|
|
|
/***********************************************************
|
|
* *
|
|
* MANAGER DES UTILISATEURS *
|
|
* *
|
|
************************************************************
|
|
* *
|
|
* [0] Constantes *
|
|
* [1] ROUTAGE de niveau 1 *
|
|
* [2] Création d'un groupe *
|
|
* *
|
|
* *
|
|
* *
|
|
* *
|
|
* *
|
|
* *
|
|
* *
|
|
* *
|
|
* *
|
|
* *
|
|
***********************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] ROUTAGE DE NIVEAU 1
|
|
============================================================*/
|
|
function groups_switch_level_1($request, $answer){
|
|
|
|
switch( $request->level_1 ){
|
|
|
|
/************************/
|
|
/* création d'un groupe */
|
|
/************************/
|
|
case 'create':
|
|
$areSetParam = isset($request->username) && isset($request->prenom) && isset($request->nom) && isset($request->email) && isset($request->password) && isset($request->droits); // les arguments existent
|
|
$typeOkParam = $areSetParam && is_string($request->username) && is_string($request->prenom) && is_string($request->nom) && is_string($request->email) && is_string($request->password) && is_string($request->droits); // ils sont tous 2 des string
|
|
$nEmptyParam = $typeOkParam && strlen($request->username) > 0 && strlen($request->prenom) > 0 && is_string($request->nom) && is_string($request->email) && is_string($request->password) && is_string($request->droits); // d'au moins 1 caractère
|
|
$usernameCheck = $nEmptyParam && preg_match('/^[\w -]{3,50}$/i', $request->username); // username bon format
|
|
$prenomCheck = $usernameCheck && preg_match('/^[a-z -]{3,50}$/i', $request->prenom); // prenom bon format
|
|
$nomCheck = $prenomCheck && preg_match('/^[a-z -]{3,50}$/i', $request->nom); // nom bon format
|
|
$emailCheck = $nomCheck && preg_match('/^[\w\.-]+@[\w\.-]+\.[a-z]{2,4}$/i', $request->email); // email bon format
|
|
$passwordCheck = $emailCheck && preg_match('/^[\w -]{6,100}$/i', $request->password); // password bon format
|
|
$droitsCheck = $passwordCheck && is_int(array_search($request->droits, ['student', 'teacher', 'master', 'admin'])); // droits bon format
|
|
|
|
if( $droitsCheck ){ // si tout les paramètres sont bons
|
|
require('database.php');
|
|
$answer->request = $db->ajouterUtilisateur($request->username, $request->prenom, $request->nom, $request->email, $request->password, $request->droits);
|
|
}else
|
|
$answer->request = 'param_error';
|
|
break;
|
|
|
|
|
|
|
|
/***********/
|
|
/* DEFAULT */
|
|
/***********/
|
|
default:
|
|
$answer->request = 'unknown_level_1';
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
?>
|