Création d'utilisateur implémentée (pas de gestion de droits pour cette action pour l'instant) + toutes les vérifications

This commit is contained in:
xdrm-brackets 2015-10-22 18:55:26 +02:00
parent 47799cde77
commit 5613157786
11 changed files with 292 additions and 82 deletions

View File

@ -1,11 +1,12 @@
#CONTAINER section{
/* position */
display: block;
position: relative;
position: absolute;
top: 0;
left: 0;
width: 100%;
/*min-height: calc( 100vh - 5em );*/
min-height: calc( 100vh - 5em );
height: auto;
padding: 2em;
/* background */

View File

@ -71,6 +71,77 @@
#HEADER .notifbar div[data-num='']::after{ content: '0'; }
/* BOUTON POUR LA DÉCONNECTION */
#HEADER .notifbar #LOGOUT{
/* position */
display: block;
margin-top: calc( 5em/2 - 2.5em/2 - 2px ); /* hauteur/2 - hauteur_bouton/2 - border_bouton/2 */
margin-left: calc( 5em/2 - 2.5em/2 - 2px ); /* hauteur/2 - hauteur_bouton/2 - border_bouton/2 */
width: calc( 2.5em - 2*2px );
height: calc( 2.5em - 2*2px );
/* border */
border-radius: 100% / 100%;
border: 2px solid #28B965;
/* background */
background: transparent url(../src/header/logout.svg) center center no-repeat;
background-size: 70% auto;
/* animation */
transition: all .1s ease-in-out, background-size 0s;
-moz-transition: all .1s ease-in-out, background-size 0s;
-webkit-transition: all 0s;
-ms-transition: all .1s ease-in-out, background-size 0s;
-o-transition: all .1s ease-in-out, background-size 0s;
/* extra */
cursor: pointer;
/* Z */
z-index: 1;
}
/* TEXTE INFO */
#HEADER .notifbar #LOGOUT[data-info]:after{
content: attr(data-info);
/* position */
/*display: block;*/ display: none;
position: absolute;
top: 1.5em;
left: 4em;
padding: .3em;
/* border */
border-radius: 3px;
/* background */
background-color: #233342;
/* foreground */
color: #fff;
}
/* BOUTON SURVOL */
#HEADER .notifbar #LOGOUT:hover{
background-color: #28B965;
background-image: url(../src/header/logout@hover.svg);
}
/* INFO SURVOL */
#HEADER .notifbar #LOGOUT[data-info]:hover:after{
display: block;
}
/* logo AGAC */
#HEADER .icon{
/* position */
@ -178,44 +249,4 @@
#SUBHEADER nav > span:hover,
#SUBHEADER nav > span.active{
border-bottom-color: #2cab5f;
}
/* BOUTON POUR LA DÉCONNECTION */
#SUBHEADER #LOGOUT{
/* position */
/*display: block;*/ display: none;
position: absolute;
top: 10px;
left: calc( 100% - 2.5em - 10px );
width: calc( 2.5em - 2*2px );
height: calc( 2.5em - 2*2px );
/* border */
border-radius: 100% / 100%;
border: 2px solid #ccc;
/* background */
background: transparent url(../src/header/logout.svg) center center no-repeat;
background-size: 70% auto;
/* animation */
transition: all .1s ease-in-out, background-size 0s;
-moz-transition: all .1s ease-in-out, background-size 0s;
-webkit-transition: all 0s;
-ms-transition: all .1s ease-in-out, background-size 0s;
-o-transition: all .1s ease-in-out, background-size 0s;
/* extra */
cursor: pointer;
}
/* BOUTON ACTIVÉ */
#SUBHEADER #LOGOUT.active{ display: block; }
/* BOUTON SURVOL */
#SUBHEADER #LOGOUT:hover{
border-color: #28B965;
background-image: url(../src/header/logout@hover.svg);
}

View File

@ -50,12 +50,6 @@
#MENU .userdata.F{ background-image: url(../src/menu/userdata/female.svg); }
/* quand on est connecté, afficher le bouton de déconnection */
#MENU .userdata.M:hover,
#MENU .userdata.F:hover{ background-image: url(../src/menu/userdata/visitor.svg); }

View File

@ -81,20 +81,36 @@ $notifNotifNum = 5;
<!-- HEADER DE LA PAGE -->
<div id='HEADER'>
<div class='notifbar'>
<!-- bouton d'ouverture du formulaire de connection/déconnection -->
<?php
<?php
/* membres */
if( $memberNotifNum > 0 ) echo "<div class='member' data-num='".$memberNotifNum."'></div>";
else echo "<div class='member'></div>";
/* messages */
if( $messageNotifNum > 0 ) echo "<div class='message' data-num='".$messageNotifNum."'></div>";
else echo "<div class='message'></div>";
if( $_SESSION['username'] != null ){ // si l'utilisateur est connecté, on affiche les notifications
/* BOUTON DE DECONNECTION */
echo "<div id='LOGOUT' data-info='Déconnection'></div>";
/* NOTIFICATIONS */
/* membres */
// if( $memberNotifNum > 0 ) echo "<div class='member' data-num='".$memberNotifNum."'></div>";
// else echo "<div class='member'></div>";
// messages
// if( $messageNotifNum > 0 ) echo "<div class='message' data-num='".$messageNotifNum."'></div>";
// else echo "<div class='message'></div>";
/* notifications */
if( $notifNotifNum > 0 ) echo "<div class='notification' data-num='".$notifNotifNum."'></div>";
else echo "<div class='notification'></div>";
}else // si l'utilisateur n'est pas connecté on affiche le bouton de CONNECTION
echo "<div id='LOGOUT' data-info='Connection'></div>";
/* notifications */
if( $notifNotifNum > 0 ) echo "<div class='notification' data-num='".$notifNotifNum."'></div>";
else echo "<div class='notification'></div>";
?>
</div>
<div class='icon'></div>
@ -102,11 +118,6 @@ $notifNotifNum = 5;
</div>
<div id='SUBHEADER'>
<?php if( $_SESSION['username'] == null )
echo "<div id='LOGOUT'></div>";
else
echo "<div id='LOGOUT' class='active'></div>";
?>
<nav>
<!-- <span data-sectname='home' class='active'>Accueil </span>

View File

@ -43,7 +43,7 @@ var DOM = {
CONTAINER : document.querySelector('#CONTAINER'),
AUTHFILTER : document.querySelector('#AUTH_FILTER'),
AUTH : document.querySelector('#AUTH'),
LOGOUT : document.querySelector('#SUBHEADER #LOGOUT')
LOGOUT : document.querySelector('#HEADER #LOGOUT')
};
@ -181,16 +181,17 @@ var connected = !( DOM.AUTH.children[0].innerHTML == 'Connection' );
/* [3] GESTION DE L'AUTHENTIFICATION
==============================================================*/
// ouvre l'interface d'authentification quand click sur zone verte
DOM.MENU.children[0].addEventListener('click', function(e){
// ouvre l'interface d'authentification quand click
DOM.LOGOUT.addEventListener('click', function(e){ // sur bouton
DOM.AUTHFILTER.className = 'active';
}, false);
if( connected ) // bouton spécial si connecté
DOM.LOGOUT.addEventListener('click', function(e){
if( !connected ) // sur zone verte si pas connecté
DOM.MENU.children[0].addEventListener('click', function(e){
DOM.AUTHFILTER.className = 'active';
}, false);
// ferme l'interface d'authentification quand clic sur filtre

View File

@ -8,11 +8,65 @@ class DataBase{
private $username;
private $password;
private $connection;
private $pdo;
public function __construct($host, $dbname, $username, $password){
this->connection = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$this->host = $host;
$this->dbname = $dbname;
$this->username = $username;
$this->password = $password;
// password: Qt358nUdyeTxLDM8
$this->pdo = new PDO('mysql:host='.$host.';dbname='.$dbname, $username, $password);
}
/*********************************************/
/*** création d'un utilisateur dans la bdd ***/
/*********************************************/
public function ajouterUtilisateur($username, $prenom, $nom, $email, $password, $droits){
$currentId = $this->pdo->lastInsertId();
// on applique une normalisation
$prenom = ucwords( strtolower($prenom) ); // majuscule à chaque mot sinon minuscule
$nom = strtoupper($nom); // nom en majuscules
$email = strtolower($email); // email en minuscules
$password = sha1($password); // on hash le password
$req = $this->pdo->prepare("INSERT INTO `utilisateurs`(`id_utilisateur`, `pseudo`, `prenom`, `nom`, `email`, `password`, `droits`) VALUES(default, :pseudo, :prenom, :nom, :email, :password, :droits)");
$req->execute(array(
':pseudo' => mysql_escape_string($username),
':prenom' => mysql_escape_string($prenom ),
':nom' => mysql_escape_string($nom ),
':email' => mysql_escape_string($email ),
':password' => mysql_escape_string($password),
':droits' => mysql_escape_string($droits )
));
// echo var_dump( $this->pdo->errorInfo() ).'<br>';
$addedId = $this->pdo->lastInsertId();
if( $currentId+1 == $addedId ) // si on a bien ajouté un entrée
return 'success';
else
return 'error';
}
/****************************************/
/*** création d'un groupe dans la bdd ***/
/****************************************/
}
$db = new DataBase("localhost", "sid", "php", "Qt358nUdyeTxLDM8");
?>

71
manager/groups.php Normal file
View File

@ -0,0 +1,71 @@
<?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;
}
}
?>

View File

@ -45,7 +45,7 @@
$typeOkParam = $areSetParam && is_string($request->username) && is_string($request->password); // ils sont tous 2 des string
$nEmptyParam = $typeOkParam && strlen($request->username) > 0 && strlen($request->password) > 0; // d'au moins 1 caractère
if( $areSetParam && $typeOkParam && $nEmptyParam )
if( $nEmptyParam )
$answer->request = user_authentification($request->username, $request->password);
else{
if ( !$areSetParam ) $answer->request= 'missing_param';
@ -66,6 +66,27 @@
$answer->request = 'error';
break;
/**************************/
/* création d'utilisateur */
/**************************/
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;
/***********/

View File

@ -15,7 +15,7 @@
inkscape:version="0.48.4 r9939"
width="100%"
height="100%"
sodipodi:docname="logout.svg"><metadata
sodipodi:docname="logout@hover.svg"><metadata
id="metadata11"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
@ -37,17 +37,17 @@
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:zoom="1.3037281"
inkscape:cx="69.503986"
inkscape:cx="87.529217"
inkscape:cy="39.059701"
inkscape:window-x="0"
inkscape:window-x="10"
inkscape:window-y="24"
inkscape:window-maximized="0"
inkscape:current-layer="Layer_1" /><path
d="m 111.87056,31.893749 16.3,16.4 c 0.4,0.4 0.6,0.9 0.6,1.4 0,0.6 -0.2,1.1 -0.6,1.4 l -16.2,16.2 c -0.8,0.8 -2,0.8 -2.8,0 -0.4,-0.4 -0.6,-0.9 -0.6,-1.4 0,-0.5 0.2,-1.1 0.6,-1.4 l 12.8,-12.9 H 58.27057 c -1.1,0 -2,-0.9 -2,-2 0,-1.1 0.9,-2 2,-2 h 63.69999 l -12.9,-12.9 c -0.4,-0.4 -0.6,-0.9 -0.6,-1.4 0,-0.5 0.2,-1 0.6,-1.4 0.7,-0.8 2,-0.8 2.8,0 z"
id="path3"
inkscape:connector-curvature="0"
style="fill:#cccccc;fill-opacity:1;stroke:#cccccc;stroke-width:1.89999998;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><path
style="fill:#28b965;fill-opacity:1;stroke:#28b965;stroke-width:1.89999998000000003;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><path
d="m 45.07057,1.5937484 h 44 c 5.5,0 10,4.5 10,10.0000006 v 16.3 h -4 v -16.3 c 0,-3.3000006 -2.7,-6.0000006 -6,-6.0000006 h -44 c -3.3,0 -6,2.7 -6,6.0000006 v 77 c 0,3.3 2.7,6 6,6 h 44 c 3.3,0 6,-2.7 6,-6 v -17.3 h 4 v 17.3 c 0,5.5 -4.5,10 -10,10 h -44 c -5.5,0 -10,-4.5 -10,-10 v -77 c 0,-5.5000006 4.5,-10.0000006 10,-10.0000006 z"
id="path5"
inkscape:connector-curvature="0"
style="fill:#cccccc;fill-opacity:1;stroke:#cccccc;stroke-width:3.20000005;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></svg>
style="fill:#28b965;fill-opacity:1;stroke:#28b965;stroke-width:3.20000004999999987;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -15,7 +15,7 @@
inkscape:version="0.48.4 r9939"
width="100%"
height="100%"
sodipodi:docname="logout@hovre.svg"><metadata
sodipodi:docname="logout.svg"><metadata
id="metadata11"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
@ -37,17 +37,17 @@
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:zoom="1.3037281"
inkscape:cx="87.529217"
inkscape:cx="-61.274817"
inkscape:cy="39.059701"
inkscape:window-x="0"
inkscape:window-x="10"
inkscape:window-y="24"
inkscape:window-maximized="0"
inkscape:current-layer="Layer_1" /><path
d="m 111.87056,31.893749 16.3,16.4 c 0.4,0.4 0.6,0.9 0.6,1.4 0,0.6 -0.2,1.1 -0.6,1.4 l -16.2,16.2 c -0.8,0.8 -2,0.8 -2.8,0 -0.4,-0.4 -0.6,-0.9 -0.6,-1.4 0,-0.5 0.2,-1.1 0.6,-1.4 l 12.8,-12.9 H 58.27057 c -1.1,0 -2,-0.9 -2,-2 0,-1.1 0.9,-2 2,-2 h 63.69999 l -12.9,-12.9 c -0.4,-0.4 -0.6,-0.9 -0.6,-1.4 0,-0.5 0.2,-1 0.6,-1.4 0.7,-0.8 2,-0.8 2.8,0 z"
id="path3"
inkscape:connector-curvature="0"
style="fill:#28b965;fill-opacity:1;stroke:#28b965;stroke-width:1.89999998000000003;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><path
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:1.89999998000000003;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><path
d="m 45.07057,1.5937484 h 44 c 5.5,0 10,4.5 10,10.0000006 v 16.3 h -4 v -16.3 c 0,-3.3000006 -2.7,-6.0000006 -6,-6.0000006 h -44 c -3.3,0 -6,2.7 -6,6.0000006 v 77 c 0,3.3 2.7,6 6,6 h 44 c 3.3,0 6,-2.7 6,-6 v -17.3 h 4 v 17.3 c 0,5.5 -4.5,10 -10,10 h -44 c -5.5,0 -10,-4.5 -10,-10 v -77 c 0,-5.5000006 4.5,-10.0000006 10,-10.0000006 z"
id="path5"
inkscape:connector-curvature="0"
style="fill:#28b965;fill-opacity:1;stroke:#28b965;stroke-width:3.20000004999999987;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></svg>
style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:3.20000004999999987;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

26
test.php Normal file
View File

@ -0,0 +1,26 @@
<?php
require('manager/user.php');
$request = new stdClass();
$answer = new stdClass();
$request->level_1 = 'create';
$request->username = 'mrd1609a';
$request->prenom = 'adrien';
$request->nom = 'ligou marques';
$request->email = 'adrien.marques-ligou@etu.iut-tlse3.fr';
$request->password = ' Test_Password _';
$request->droits = 'student';
user_switch_level_1($request, $answer);
echo var_dump( $answer );
echo "<br><br><br><br><br><br><br>It works !";
?>