mise en place d'api rest (fixes #13)

This commit is contained in:
afornerot 2019-08-20 09:42:41 +02:00
parent 1516765e76
commit 611436eb89
5 changed files with 134 additions and 2 deletions

View File

@ -49,6 +49,7 @@
<variable type='string' name='ninegate_masteridentity' description="Maître de l'Identité" mandatory='True'><value>LDAP</value></variable> <variable type='string' name='ninegate_masteridentity' description="Maître de l'Identité" mandatory='True'><value>LDAP</value></variable>
<variable type='string' name='ninegate_mode_auth' description="Mode Authentification" mandatory='True'><value>CAS</value></variable> <variable type='string' name='ninegate_mode_auth' description="Mode Authentification" mandatory='True'><value>CAS</value></variable>
<variable type='string' name='ninegate_api_key' description="Clé d'accès API" mandatory='True'><value>APIKeyNinegate</value></variable>
<variable type='oui/non' name='ninegate_syncldap' description="Synchroniser Ninegate vers votre annuaire"><value>non</value></variable> <variable type='oui/non' name='ninegate_syncldap' description="Synchroniser Ninegate vers votre annuaire"><value>non</value></variable>
<variable type='oui/non' name='ninegate_synceportail' description="Synchroniser Ninegate vers ePortail"><value>non</value></variable> <variable type='oui/non' name='ninegate_synceportail' description="Synchroniser Ninegate vers ePortail"><value>non</value></variable>
@ -178,7 +179,7 @@
<variable type='string' name='ninegate_websocket_portexterne' description='Port de commuinication externe du serveur Websocket' mandatory='True' > <variable type='string' name='ninegate_websocket_portexterne' description='Port de commuinication externe du serveur Websocket' mandatory='True' >
<value>5555</value> <value>5555</value>
</variable> </variable>
<variable type='string' name='ninegate_websocket_portinterne' description='Port de commuinication externe du serveur Websocket' mandatory='True'> <variable type='string' name='ninegate_websocket_portinterne' description='Port de commuinication interne du serveur Websocket' mandatory='True'>
<value>5556</value> <value>5556</value>
</variable> </variable>
@ -231,6 +232,7 @@
<target type='variable'>ninegate_masteridentity</target> <target type='variable'>ninegate_masteridentity</target>
<target type='variable'>ninegate_mode_auth</target> <target type='variable'>ninegate_mode_auth</target>
<target type='variable'>ninegate_api_key</target>
<target type='variable'>ninegate_syncldap</target> <target type='variable'>ninegate_syncldap</target>

View File

@ -8,7 +8,7 @@ INSERT IGNORE INTO `niveau01` (`id`, `label`, `siren`) VALUES
(-100, 'DRAAF', '130007107'); (-100, 'DRAAF', '130007107');
INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES
(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}MBogNANkXtDRLDro8qSoCT65Wcm00zzJ (-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}9cnVg+DTTmS1xmuUKkR7E2gsmtYyea6r
', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple'); ', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple');

View File

@ -0,0 +1,123 @@
<?php
namespace Cadoles\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Form\FormError;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Cadoles\CoreBundle\Entity\User;
use Cadoles\CoreBundle\Entity\UserGroup;
use Cadoles\CoreBundle\Entity\UserModo;
use Cadoles\CoreBundle\Entity\Niveau01;
use Cadoles\CoreBundle\Entity\Niveau02;
use Cadoles\WebsocketBundle\Entity\Message;
use Cadoles\CoreBundle\Form\UserType;
class RestController extends Controller
{
public function userAction($key, $login, Request $request)
{
// Vérification de la clé
$realkey = $this->getParameter("apikeyninegate");
if($key!=$realkey) {
$output["error"]="error key";
return new Response(json_encode($output), 400);
}
$em = $this->getDoctrine()->getManager();
$output = [];
// Récupérer l'utilisateur
$user=$em->getRepository('CadolesCoreBundle:User')->findOneBy(["username"=>$login]);
if(!$user) {
$output["error"]="user not exist";
return new Response(json_encode($output), 400);
}
// Format de sortie
$output["user"] = [];
$output["bookmarks"] = [];
$output["items"] = [];
$output["itemcategorys"] = [];
$bookmarks=null;
$items=null;
$itemcategorys=null;
$weburl="https://".$this->getParameter("weburl")."/".$this->getParameter("alias")."/";
$em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,3);
// Construction de la réponse
$output["user"]["firstname"] = $user->getFirstname();
$output["user"]["lasttname"] = $user->getLastname();
$output["user"]["email"] = $user->getEmail();
$output["user"]["avatar"] = $weburl."uploads/avatar/".$user->getAvatar();
$output["user"]["niveau01"] = $user->getNiveau01()->getLabel();
$output["user"]["niveau02"] = ($user->getNiveau02()?$user->getNiveau02()->getLabel():null);
if($bookmarks) {
foreach($bookmarks as $bookmark) {
$tmp=[];
$tmp["id"] = $bookmark->getId();
$tmp["title"] = $bookmark->getTitle();
$tmp["url"] = $bookmark->getUrl();
$tmp["target"] = $bookmark->getTarget();
$tmp["order"] = 0;
$tmp["color"] = ($bookmark->getColor()?$bookmark->getColor():$this->get('session')->get('color')["main"]);
$tmp["icon"] = $weburl.($bookmark->getIcon()?$bookmark->getIcon()->getLabel():"uploads/icon/icon_pin.png");
array_push($output["bookmarks"],$tmp);
}
}
if($items) {
foreach($items as $item) {
$tmp=[];
$tmp["id"] = $item->getId();
$tmp["title"] = $item->getTitle();
$tmp["url"] = $item->getUrl();
$tmp["target"] = $item->getTarget();
$tmp["order"] = $item->getRoworder();
$tmp["color"] = ($item->getColor()?$item->getColor():$this->get('session')->get('color')["main"]);
$tmp["icon"] = $weburl.($item->getIcon()?$item->getIcon()->getLabel():"uploads/icon/icon_pin.png");
$tmp["essential"] = $item->getEssential();
$tmp["category"] = $item->getItemcategory()->getId();
array_push($output["items"],$tmp);
}
}
if($itemcategorys) {
foreach($itemcategorys as $itemcategory) {
$tmp=[];
$tmp["id"] = $itemcategory->getId();
$tmp["title"] = $itemcategory->getLabel();
$tmp["order"] = $itemcategory->getRoworder();
$tmp["color"] = ($itemcategory->getColor()?$itemcategory->getColor():$this->get('session')->get('color')["main"]);
array_push($output["itemcategorys"],$tmp);
}
}
// Retour
return new Response(json_encode($output), 200);
}
}

View File

@ -432,3 +432,7 @@ cadoles_core_config_whitelist_ajax_list:
#== REST ==================================================================================================================
cadoles_core_rest_user:
path: /rest/user/{key}/{login}
defaults: { _controller: CadolesCoreBundle:Rest:user }

View File

@ -13,6 +13,9 @@ parameters:
# Car aucune synchronisation des password n'est possible # Car aucune synchronisation des password n'est possible
mode_auth: %%ninegate_mode_auth mode_auth: %%ninegate_mode_auth
# API Key
apikeyninegate: %%ninegate_api_key
# Mode de registration : none / byuser / byadmin # Mode de registration : none / byuser / byadmin
# none = désactivation de l'inscription mais reset de password possible # none = désactivation de l'inscription mais reset de password possible
# byuser = aucune validation par un administrateur, l'utilisateur valide son inscription par lui-même # byuser = aucune validation par un administrateur, l'utilisateur valide son inscription par lui-même