fix(continuous-integration): correction php-cs-fixer
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
All checks were successful
Cadoles/nineskeletor/pipeline/pr-master This commit looks good
This commit is contained in:
@ -1,38 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use App\Entity\Audit as Entity;
|
||||
use App\Form\AuditType as Form;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AuditController extends AbstractController
|
||||
{
|
||||
private $data="audit";
|
||||
private $entity="App\Entity\Audit";
|
||||
private $twig="Audit/";
|
||||
private $route="app_admin_audit";
|
||||
|
||||
public function list($entityname,$access,ManagerRegistry $em): Response
|
||||
{
|
||||
$datas = $em->getRepository($this->entity)->findBy(["entityname"=>$entityname]);
|
||||
private $data = 'audit';
|
||||
private $entity = "App\Entity\Audit";
|
||||
private $twig = 'Audit/';
|
||||
private $route = 'app_admin_audit';
|
||||
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
"entityname" => $entityname,
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
public function list($entityname, $access, ManagerRegistry $em): Response
|
||||
{
|
||||
$datas = $em->getRepository($this->entity)->findBy(['entityname' => $entityname]);
|
||||
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
$this->data.'s' => $datas,
|
||||
'entityname' => $entityname,
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function auditrender($entityname,$entityid,$access,ManagerRegistry $em): Response
|
||||
{
|
||||
$datas = $em->getRepository($this->entity)->findBy(["entityname"=>$entityname,"entityid"=>$entityid]);
|
||||
|
||||
public function auditrender($entityname, $entityid, $access, ManagerRegistry $em): Response
|
||||
{
|
||||
$datas = $em->getRepository($this->entity)->findBy(['entityname' => $entityname, 'entityid' => $entityid]);
|
||||
|
||||
/*
|
||||
if($entityname=="User") {
|
||||
$user=$em->getRepository("App\Entity\User")->find($entityid);
|
||||
@ -52,8 +50,8 @@ class AuditController extends AbstractController
|
||||
}
|
||||
*/
|
||||
|
||||
return $this->render($this->twig.'render.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
return $this->render($this->twig.'render.html.twig', [
|
||||
$this->data.'s' => $datas,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,86 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Form\ConfigType as Form;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use App\Entity\Config as Entity;
|
||||
use App\Form\ConfigType as Form;
|
||||
|
||||
class ConfigController extends AbstractController
|
||||
{
|
||||
private $data="config";
|
||||
private $entity="App\Entity\Config";
|
||||
private $twig="Config/";
|
||||
private $route="app_admin_config";
|
||||
|
||||
private $data = 'config';
|
||||
private $entity = "App\Entity\Config";
|
||||
private $twig = 'Config/';
|
||||
private $route = 'app_admin_config';
|
||||
|
||||
public function list($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"access"=>$access,
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function listrender($access,$category,ManagerRegistry $em): Response
|
||||
{
|
||||
$datas = $em->getRepository($this->entity)->findBy(["visible"=>true,"category"=>$category]);
|
||||
public function listrender($access, $category, ManagerRegistry $em): Response
|
||||
{
|
||||
$datas = $em->getRepository($this->entity)->findBy(['visible' => true, 'category' => $category]);
|
||||
|
||||
return $this->render($this->twig.'render.html.twig',[
|
||||
$this->data."s" => $datas,
|
||||
return $this->render($this->twig.'render.html.twig', [
|
||||
$this->data.'s' => $datas,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($access,$id,Request $request,ManagerRegistry $em): Response
|
||||
public function update($access, $id, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if(!$data->getValue())
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data->getValue()) {
|
||||
$data->setValue($request->getSession()->get($data->getId()));
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update","id"=>$data->getId(),"type"=>$data->getType(),"required"=>$data->isRequired()));
|
||||
$form = $this->createForm(Form::class, $data, ['mode' => 'update', 'id' => $data->getId(), 'type' => $data->getType(), 'required' => $data->isRequired()]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView()
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($access,$id,Request $request,ManagerRegistry $em): Response
|
||||
public function delete($access, $id, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$config=$em->getRepository($this->entity)->find($id);
|
||||
if(!$config->isRequired()) {
|
||||
$config->setValue("");
|
||||
$em->getManager()->flush();
|
||||
$config = $em->getRepository($this->entity)->find($id);
|
||||
if (!$config->isRequired()) {
|
||||
$config->setValue('');
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
public function logo($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'logo.html.twig');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,183 +2,186 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use App\Form\CronType as Form;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
use App\Form\CronType as Form;
|
||||
|
||||
class CronController extends AbstractController
|
||||
{
|
||||
private $data="cron";
|
||||
private $entity="App\Entity\Cron";
|
||||
private $twig="Cron/";
|
||||
private $route="app_admin_cron";
|
||||
|
||||
private $data = 'cron';
|
||||
private $entity = "App\Entity\Cron";
|
||||
private $twig = 'Cron/';
|
||||
private $route = 'app_admin_cron';
|
||||
|
||||
public function list($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"access"=>$access,
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function tablelist(Request $request,ManagerRegistry $em): Response
|
||||
{
|
||||
$query=$request->query->all();
|
||||
$start=$query['start'];
|
||||
$length=$query['length'];
|
||||
$search=$query['search'];
|
||||
$draw= $query['draw'];
|
||||
$ordercolumn=$query['order'][0]['column'];
|
||||
$orderdir=$query['order'][0]['dir'];
|
||||
public function tablelist(Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$query = $request->query->all();
|
||||
$start = $query['start'];
|
||||
$length = $query['length'];
|
||||
$search = $query['search'];
|
||||
$draw = $query['draw'];
|
||||
$ordercolumn = $query['order'][0]['column'];
|
||||
$orderdir = $query['order'][0]['dir'];
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity,'entity')->getQuery()->getSingleScalarResult();
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if(!$search||$search["value"]=="")
|
||||
if (!$search || '' == $search['value']) {
|
||||
$totalf = $total;
|
||||
else {
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->where('entity.command LIKE :value OR entity.description LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('entity')->from($this->entity,'entity');
|
||||
if($search&&$search["value"]!="") {
|
||||
$qb ->andWhere('entity.command LIKE :value OR entity.description LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
$qb->select('entity')->from($this->entity, 'entity');
|
||||
if ($search && '' != $search['value']) {
|
||||
$qb->andWhere('entity.command LIKE :value OR entity.description LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
|
||||
if($ordercolumn) {
|
||||
switch($ordercolumn) {
|
||||
case 1 :
|
||||
$qb->orderBy('entity.nextexecdate',$orderdir);
|
||||
break;
|
||||
if ($ordercolumn) {
|
||||
switch ($ordercolumn) {
|
||||
case 1:
|
||||
$qb->orderBy('entity.nextexecdate', $orderdir);
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
$qb->orderBy('entity.command',$orderdir);
|
||||
break;
|
||||
case 2:
|
||||
$qb->orderBy('entity.command', $orderdir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach($datas as $data) {
|
||||
foreach ($datas as $data) {
|
||||
// Action
|
||||
$action = "";
|
||||
$action.="<a href='".$this->generateUrl($this->route.'_update', array('id'=>$data->getId()))."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
$action = '';
|
||||
$action .= "<a href='".$this->generateUrl($this->route.'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
|
||||
$tmp=array();
|
||||
array_push($tmp,$action);
|
||||
array_push($tmp,$data->getNextexecdate()->format("d/m/Y H:i"));
|
||||
array_push($tmp,$data->getCommand());
|
||||
array_push($tmp,$data->getDescription());
|
||||
array_push($tmp,$data->getStatutLabel());
|
||||
$tmp = [];
|
||||
array_push($tmp, $action);
|
||||
array_push($tmp, $data->getNextexecdate()->format('d/m/Y H:i'));
|
||||
array_push($tmp, $data->getCommand());
|
||||
array_push($tmp, $data->getDescription());
|
||||
array_push($tmp, $data->getStatutLabel());
|
||||
|
||||
array_push($output["data"],$tmp);
|
||||
array_push($output['data'], $tmp);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function update($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"update",
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'update',
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'access' => $access,
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function log()
|
||||
{
|
||||
return $this->render($this->twig.'logs.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getlog(Request $request, $id)
|
||||
{
|
||||
|
||||
$path = $this->getParameter('kernel.project_dir');
|
||||
if($id=="dump")
|
||||
$file = $path . '/var/log/' . $this->getParameter("appAlias") . '.sql';
|
||||
else
|
||||
$file = $path . '/var/log/'.$id.'.log';
|
||||
|
||||
$fs = new Filesystem();
|
||||
if($fs->exists($file)) {
|
||||
$response = new BinaryFileResponse($file);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
|
||||
return $response;
|
||||
}
|
||||
else return $this->redirectToRoute($this->route."_log");
|
||||
}
|
||||
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode) {
|
||||
if ($form->get('submit')->isClicked()&&$mode=="delete") {
|
||||
if ('dump' == $id) {
|
||||
$file = $path.'/var/log/'.$this->getParameter('appAlias').'.sql';
|
||||
} else {
|
||||
$file = $path.'/var/log/'.$id.'.log';
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
$fs = new Filesystem();
|
||||
if ($fs->exists($file)) {
|
||||
$response = new BinaryFileResponse($file);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
|
||||
|
||||
return $response;
|
||||
} else {
|
||||
return $this->redirectToRoute($this->route.'_log');
|
||||
}
|
||||
}
|
||||
|
||||
protected function getErrorForm($id, $form, $request, $data, $mode)
|
||||
{
|
||||
if ($form->get('submit')->isClicked() && 'delete' == $mode) {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && 'submit' == $mode) {
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
foreach ($errors as $error) {
|
||||
$request->getSession()->getFlashBag()->add('error', $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Service\MinioService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
class CropController extends AbstractController
|
||||
{
|
||||
@ -23,81 +23,82 @@ class CropController extends AbstractController
|
||||
}
|
||||
|
||||
// Etape 01 - Téléchargement de l'image
|
||||
public function crop01($type,$reportinput): Response
|
||||
public function crop01($type, $reportinput): Response
|
||||
{
|
||||
return $this->render('Crop/crop01.html.twig',[
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'type' => $type,
|
||||
'reportinput' => $reportinput
|
||||
return $this->render('Crop/crop01.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'type' => $type,
|
||||
'reportinput' => $reportinput,
|
||||
]);
|
||||
}
|
||||
|
||||
// Etape 02 - Couper votre l'image
|
||||
public function crop02($type,$reportinput,Request $request)
|
||||
public function crop02($type, $reportinput, Request $request)
|
||||
{
|
||||
// Récupération de l'image à cropper
|
||||
$file=$request->query->get('file');
|
||||
$large_image_location=$this->minio->download($type."/".$file,$type."/".$file,true);
|
||||
$file = $request->query->get('file');
|
||||
$large_image_location = $this->minio->download($type.'/'.$file, $type.'/'.$file, true);
|
||||
|
||||
// Récupérer les tailles de l'image
|
||||
$width = $this->getWidth($large_image_location);
|
||||
$height = $this->getHeight($large_image_location);
|
||||
$max_height=null;
|
||||
$max_width=null;
|
||||
$ratio=null;
|
||||
$width = $this->getWidth($large_image_location);
|
||||
$height = $this->getHeight($large_image_location);
|
||||
$max_height = null;
|
||||
$max_width = null;
|
||||
$ratio = null;
|
||||
|
||||
// Définir le pourcentage de réduction de l'image
|
||||
switch ($type) {
|
||||
case "illustration":
|
||||
$max_height=0;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
|
||||
case "avatar":
|
||||
$max_height=900;
|
||||
$max_width=900;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
case "header":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$ratio="16:2";
|
||||
switch ($type) {
|
||||
case 'illustration':
|
||||
$max_height = 0;
|
||||
$ratio = '1:1';
|
||||
break;
|
||||
|
||||
case 'avatar':
|
||||
$max_height = 900;
|
||||
$max_width = 900;
|
||||
$ratio = '1:1';
|
||||
break;
|
||||
case 'header':
|
||||
$max_height = 1600;
|
||||
$max_width = 1600;
|
||||
$ratio = '16:2';
|
||||
break;
|
||||
case 'hero':
|
||||
$max_height = 1600;
|
||||
$max_width = 1600;
|
||||
$ratio = '16:9';
|
||||
break;
|
||||
case 'image':
|
||||
$max_height = 1600;
|
||||
$max_width = 1600;
|
||||
$ratio = '1:1';
|
||||
break;
|
||||
case "hero":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$ratio="16:9";
|
||||
break;
|
||||
case "image":
|
||||
$max_height=1600;
|
||||
$max_width=1600;
|
||||
$ratio="1:1";
|
||||
break;
|
||||
}
|
||||
|
||||
if($max_height>0) {
|
||||
$scale = $max_height/$height;
|
||||
if(($width*$scale)>$max_width) {
|
||||
$scale = $max_width/$width;
|
||||
}
|
||||
$this->resizeImage($large_image_location,$width,$height,$scale);
|
||||
$this->minio->upload($large_image_location,$type."/".$file,false);
|
||||
}
|
||||
else $scale=1;
|
||||
|
||||
if ($max_height > 0) {
|
||||
$scale = $max_height / $height;
|
||||
if (($width * $scale) > $max_width) {
|
||||
$scale = $max_width / $width;
|
||||
}
|
||||
$this->resizeImage($large_image_location, $width, $height, $scale);
|
||||
$this->minio->upload($large_image_location, $type.'/'.$file, false);
|
||||
} else {
|
||||
$scale = 1;
|
||||
}
|
||||
|
||||
// Construction du formulaire
|
||||
$submited=false;
|
||||
$submited = false;
|
||||
$form = $this->createFormBuilder()
|
||||
->add('submit',SubmitType::class,array("label" => "Valider","attr" => array("class" => "btn btn-success")))
|
||||
->add('x',HiddenType::class)
|
||||
->add('y',HiddenType::class)
|
||||
->add('w',HiddenType::class)
|
||||
->add('h',HiddenType::class)
|
||||
->add('xs',HiddenType::class)
|
||||
->add('ys',HiddenType::class)
|
||||
->add('ws',HiddenType::class)
|
||||
->add('hs',HiddenType::class)
|
||||
->add('submit', SubmitType::class, ['label' => 'Valider', 'attr' => ['class' => 'btn btn-success']])
|
||||
->add('x', HiddenType::class)
|
||||
->add('y', HiddenType::class)
|
||||
->add('w', HiddenType::class)
|
||||
->add('h', HiddenType::class)
|
||||
->add('xs', HiddenType::class)
|
||||
->add('ys', HiddenType::class)
|
||||
->add('ws', HiddenType::class)
|
||||
->add('hs', HiddenType::class)
|
||||
->getForm();
|
||||
|
||||
// Récupération des data du formulaire
|
||||
@ -107,134 +108,141 @@ class CropController extends AbstractController
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
// Récupération des valeurs du formulaire
|
||||
$data = $form->getData();
|
||||
$tmpdir=$this->appKernel->getProjectDir()."/var/tmp";
|
||||
$thumb_image_location = "$tmpdir/$type/thumb_".$file;
|
||||
$cropped = $this->resizeThumbnailImage($thumb_image_location, $large_image_location,$data["ws"],$data["hs"],$data["xs"],$data["ys"],$scale);
|
||||
$tmpdir = $this->appKernel->getProjectDir().'/var/tmp';
|
||||
$thumb_image_location = "$tmpdir/$type/thumb_".$file;
|
||||
$cropped = $this->resizeThumbnailImage($thumb_image_location, $large_image_location, $data['ws'], $data['hs'], $data['xs'], $data['ys'], $scale);
|
||||
|
||||
// Dépot des fichiers sur minio
|
||||
$this->minio->upload($thumb_image_location,$type."/thumb_".$file,false);
|
||||
$this->minio->upload($thumb_image_location, $type.'/thumb_'.$file, false);
|
||||
|
||||
$submited=true;
|
||||
$submited = true;
|
||||
}
|
||||
|
||||
return $this->render('Crop/crop02.html.twig', [
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'form' => $form->createView(),
|
||||
'type' => $type,
|
||||
'file' => $file,
|
||||
'ratio' => $ratio,
|
||||
"reportinput" => $reportinput,
|
||||
"submited" => $submited
|
||||
'useheader' => false,
|
||||
'usesidebar' => false,
|
||||
'form' => $form->createView(),
|
||||
'type' => $type,
|
||||
'file' => $file,
|
||||
'ratio' => $ratio,
|
||||
'reportinput' => $reportinput,
|
||||
'submited' => $submited,
|
||||
]);
|
||||
}
|
||||
|
||||
// Calcul de la hauteur
|
||||
protected function getHeight($image) {
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
return $height;
|
||||
}
|
||||
// Calcul de la hauteur
|
||||
protected function getHeight($image)
|
||||
{
|
||||
$size = getimagesize($image);
|
||||
$height = $size[1];
|
||||
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image) {
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
return $width;
|
||||
}
|
||||
return $height;
|
||||
}
|
||||
|
||||
protected function resizeImage($image,$width,$height,$scale) {
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
$source=null;
|
||||
// Cacul de la largeur
|
||||
protected function getWidth($image)
|
||||
{
|
||||
$size = getimagesize($image);
|
||||
$width = $size[0];
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
imagecopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$width,$height);
|
||||
return $width;
|
||||
}
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
imagejpeg($newImage,$image,90);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$image);
|
||||
break;
|
||||
}
|
||||
protected function resizeImage($image, $width, $height, $scale)
|
||||
{
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
|
||||
$source = null;
|
||||
|
||||
chmod($image, 0640);
|
||||
return $image;
|
||||
}
|
||||
switch ($imageType) {
|
||||
case 'image/gif':
|
||||
$source = imagecreatefromgif($image);
|
||||
break;
|
||||
case 'image/pjpeg':
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
$source = imagecreatefromjpeg($image);
|
||||
break;
|
||||
case 'image/png':
|
||||
case 'image/x-png':
|
||||
$source = imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
imagecopyresampled($newImage, $source, 0, 0, 0, 0, $newImageWidth, $newImageHeight, $width, $height);
|
||||
|
||||
protected function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
|
||||
switch ($imageType) {
|
||||
case 'image/gif':
|
||||
imagegif($newImage, $image);
|
||||
break;
|
||||
case 'image/pjpeg':
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
imagejpeg($newImage, $image, 90);
|
||||
break;
|
||||
case 'image/png':
|
||||
case 'image/x-png':
|
||||
imagepng($newImage, $image);
|
||||
break;
|
||||
}
|
||||
|
||||
chmod($image, 0640);
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale)
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
$fs->remove($thumb_image_name);
|
||||
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImageWidth=900;
|
||||
$newImageHeight=900;
|
||||
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
|
||||
$source=null;
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
$source=imagecreatefromgif($image);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
dump("here");
|
||||
$source=imagecreatefromjpeg($image);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
$source=imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
|
||||
$imageType = image_type_to_mime_type($imageType);
|
||||
$newImageWidth = ceil($width * $scale);
|
||||
$newImageHeight = ceil($height * $scale);
|
||||
$newImageWidth = 900;
|
||||
$newImageHeight = 900;
|
||||
$newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
|
||||
$source = null;
|
||||
|
||||
$ok=imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
|
||||
switch ($imageType) {
|
||||
case 'image/gif':
|
||||
$source = imagecreatefromgif($image);
|
||||
break;
|
||||
case 'image/pjpeg':
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
dump('here');
|
||||
$source = imagecreatefromjpeg($image);
|
||||
break;
|
||||
case 'image/png':
|
||||
case 'image/x-png':
|
||||
$source = imagecreatefrompng($image);
|
||||
break;
|
||||
}
|
||||
|
||||
switch($imageType) {
|
||||
case "image/gif":
|
||||
imagegif($newImage,$thumb_image_name);
|
||||
break;
|
||||
case "image/pjpeg":
|
||||
case "image/jpeg":
|
||||
case "image/jpg":
|
||||
$ok = imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
|
||||
|
||||
switch ($imageType) {
|
||||
case 'image/gif':
|
||||
imagegif($newImage, $thumb_image_name);
|
||||
break;
|
||||
case 'image/pjpeg':
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
dump($thumb_image_name);
|
||||
imagejpeg($newImage,$thumb_image_name,100);
|
||||
break;
|
||||
case "image/png":
|
||||
case "image/x-png":
|
||||
imagepng($newImage,$thumb_image_name);
|
||||
break;
|
||||
}
|
||||
imagejpeg($newImage, $thumb_image_name, 100);
|
||||
break;
|
||||
case 'image/png':
|
||||
case 'image/x-png':
|
||||
imagepng($newImage, $thumb_image_name);
|
||||
break;
|
||||
}
|
||||
|
||||
chmod($thumb_image_name, 0640);
|
||||
return $thumb_image_name;
|
||||
}
|
||||
|
||||
return $thumb_image_name;
|
||||
}
|
||||
}
|
||||
|
@ -1,695 +1,720 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Entity\Group as Entity;
|
||||
use App\Entity\UserGroup;
|
||||
use App\Form\GroupType as Form;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class GroupController extends AbstractController
|
||||
{
|
||||
private $data="group";
|
||||
private $entity="App\Entity\Group";
|
||||
private $twig="Group/";
|
||||
private $route="app_admin_group";
|
||||
|
||||
private $data = 'group';
|
||||
private $entity = "App\Entity\Group";
|
||||
private $twig = 'Group/';
|
||||
private $route = 'app_admin_group';
|
||||
|
||||
public function list($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>($access!="user"),
|
||||
"access"=>$access,
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => ('user' != $access),
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function tablelist($access,Request $request,ManagerRegistry $em): Response
|
||||
{
|
||||
$query=$request->query->all();
|
||||
$start=$query['start'];
|
||||
$length=$query['length'];
|
||||
$search=$query['search'];
|
||||
$draw= $query['draw'];
|
||||
$ordercolumn=$query['order'][0]['column'];
|
||||
$orderdir=$query['order'][0]['dir'];
|
||||
$user=$this->getUser();
|
||||
public function tablelist($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$query = $request->query->all();
|
||||
$start = $query['start'];
|
||||
$length = $query['length'];
|
||||
$search = $query['search'];
|
||||
$draw = $query['draw'];
|
||||
$ordercolumn = $query['order'][0]['column'];
|
||||
$orderdir = $query['order'][0]['dir'];
|
||||
$user = $this->getUser();
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('COUNT(entity)')->from($this->entity,'entity')->getQuery()->getSingleScalarResult();
|
||||
if($access=="user") {
|
||||
$qb ->from("App:UserGroup","usergroup")
|
||||
->andWhere(("entity.isworkgroup=:flag"))
|
||||
->andWhere("entity.id=usergroup.group")
|
||||
->andWhere("usergroup.user=:user")
|
||||
->setParameter("flag", true)
|
||||
->setParameter("user", $user);
|
||||
|
||||
$qb->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
||||
if ('user' == $access) {
|
||||
$qb->from('App:UserGroup', 'usergroup')
|
||||
->andWhere('entity.isworkgroup=:flag')
|
||||
->andWhere('entity.id=usergroup.group')
|
||||
->andWhere('usergroup.user=:user')
|
||||
->setParameter('flag', true)
|
||||
->setParameter('user', $user);
|
||||
}
|
||||
$total = $qb->getQuery()->getSingleScalarResult();
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if(!$search||$search["value"]=="")
|
||||
if (!$search || '' == $search['value']) {
|
||||
$totalf = $total;
|
||||
else {
|
||||
$qb= $em->getManager()->createQueryBuilder();
|
||||
|
||||
$qb ->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
} else {
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('COUNT(entity)')
|
||||
->from($this->entity, 'entity')
|
||||
->where('entity.label LIKE :value')
|
||||
->leftJoin('App:User', 'user','WITH','entity.owner = user.id AND user.username LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->leftJoin('App:User', 'user', 'WITH', 'entity.owner = user.id AND user.username LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
if($access=="user") {
|
||||
$qb ->from("App:UserGroup","usergroup")
|
||||
->andWhere(("entity.isworkgroup=:flag"))
|
||||
->andWhere("entity.id=usergroup.group")
|
||||
->andWhere("usergroup.user=:user")
|
||||
->setParameter("flag", true)
|
||||
->setParameter("user", $user);
|
||||
}
|
||||
$totalf= $qb->getQuery()->getSingleScalarResult();
|
||||
if ('user' == $access) {
|
||||
$qb->from('App:UserGroup', 'usergroup')
|
||||
->andWhere('entity.isworkgroup=:flag')
|
||||
->andWhere('entity.id=usergroup.group')
|
||||
->andWhere('usergroup.user=:user')
|
||||
->setParameter('flag', true)
|
||||
->setParameter('user', $user);
|
||||
}
|
||||
$totalf = $qb->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb ->select('entity')
|
||||
->from($this->entity,'entity');
|
||||
if($access=="user") {
|
||||
$qb ->from("App:UserGroup","usergroup")
|
||||
->andWhere(("entity.isworkgroup=:flag"))
|
||||
->andWhere("entity.id=usergroup.group")
|
||||
->andWhere("usergroup.user=:user")
|
||||
->setParameter("flag", true)
|
||||
->setParameter("user", $user);
|
||||
$qb->select('entity')
|
||||
->from($this->entity, 'entity');
|
||||
if ('user' == $access) {
|
||||
$qb->from('App:UserGroup', 'usergroup')
|
||||
->andWhere('entity.isworkgroup=:flag')
|
||||
->andWhere('entity.id=usergroup.group')
|
||||
->andWhere('usergroup.user=:user')
|
||||
->setParameter('flag', true)
|
||||
->setParameter('user', $user);
|
||||
}
|
||||
|
||||
if($search&&$search["value"]!="") {
|
||||
$qb ->andWhere('entity.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
if ($search && '' != $search['value']) {
|
||||
$qb->andWhere('entity.label LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
|
||||
if($ordercolumn) {
|
||||
switch($ordercolumn) {
|
||||
case 1 :
|
||||
$qb->orderBy('entity.label',$orderdir);
|
||||
break;
|
||||
case 2 :
|
||||
$qb->orderBy('entity.isworkgroup',$orderdir);
|
||||
break;
|
||||
case 3 :
|
||||
$qb->orderBy('entity.isopen',$orderdir);
|
||||
break;
|
||||
case 4 :
|
||||
$qb->orderBy('entity.owner',$orderdir);
|
||||
break;
|
||||
if ($ordercolumn) {
|
||||
switch ($ordercolumn) {
|
||||
case 1:
|
||||
$qb->orderBy('entity.label', $orderdir);
|
||||
break;
|
||||
case 2:
|
||||
$qb->orderBy('entity.isworkgroup', $orderdir);
|
||||
break;
|
||||
case 3:
|
||||
$qb->orderBy('entity.isopen', $orderdir);
|
||||
break;
|
||||
case 4:
|
||||
$qb->orderBy('entity.owner', $orderdir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach($datas as $data) {
|
||||
foreach ($datas as $data) {
|
||||
// Action
|
||||
$action = "";
|
||||
switch($access) {
|
||||
case "admin":
|
||||
if($this->canupdate($access,$data,$em,false))
|
||||
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_update', ['id'=>$data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
$action = '';
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
if ($this->canupdate($access, $data, $em, false)) {
|
||||
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
}
|
||||
|
||||
if($this->canseemember($access,$data,$em,false))
|
||||
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_users', ['id'=>$data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
if ($this->canseemember($access, $data, $em, false)) {
|
||||
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_users', ['id' => $data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
|
||||
}
|
||||
break;
|
||||
|
||||
case "modo":
|
||||
if($this->canupdate($access,$data,$em,false))
|
||||
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_update', ['id'=>$data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
case 'modo':
|
||||
if ($this->canupdate($access, $data, $em, false)) {
|
||||
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
}
|
||||
|
||||
if($this->canseemember($access,$data,$em,false))
|
||||
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_users', ['id'=>$data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
if ($this->canseemember($access, $data, $em, false)) {
|
||||
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_users', ['id' => $data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
|
||||
}
|
||||
break;
|
||||
|
||||
case "user":
|
||||
if($this->canupdate($access,$data,$em,false))
|
||||
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_update', ['id'=>$data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
|
||||
if($this->canseemember($access,$data,$em,false))
|
||||
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_users', ['id'=>$data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
|
||||
case 'user':
|
||||
if ($this->canupdate($access, $data, $em, false)) {
|
||||
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
}
|
||||
|
||||
if ($this->canseemember($access, $data, $em, false)) {
|
||||
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_users', ['id' => $data->getId()])."'><i class='fa fa-users fa-fw fa-2x'></i></a>";
|
||||
}
|
||||
|
||||
// On ne peut se désinscrire que si le groupe est ouvert et qu'il n'est pas lié à un groupe ldap ou sso
|
||||
if($data->getOwner()!=$this->getUser()&&($data->isIsOpen()||$this->canupdatemember($access,$data,$em,false)))
|
||||
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_".$access."_",$this->route).'_userout', ['id'=>$data->getId()])."'><i class='fa fa-sign-out-alt fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
if ($data->getOwner() != $this->getUser() && ($data->isIsOpen() || $this->canupdatemember($access, $data, $em, false))) {
|
||||
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_'.$access.'_', $this->route).'_userout', ['id' => $data->getId()])."'><i class='fa fa-sign-out-alt fa-fw fa-2x'></i></a>";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$userinfo="";
|
||||
if($data->getOwner()) {
|
||||
$userinfo.="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getOwner()->getAvatar()])."' class='avatar'>";
|
||||
$userinfo.="<br>".$data->getOwner()->getUsername();
|
||||
$userinfo = '';
|
||||
if ($data->getOwner()) {
|
||||
$userinfo .= "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getOwner()->getAvatar()])."' class='avatar'>";
|
||||
$userinfo .= '<br>'.$data->getOwner()->getUsername();
|
||||
}
|
||||
|
||||
$visitecpt=0;
|
||||
$visitelast=null;
|
||||
foreach($data->getUsers() as $usergroup) {
|
||||
$visitecpt+=intval($usergroup->getVisitecpt());
|
||||
$visitelast=($usergroup->getVisitedate()>$visitelast?$usergroup->getVisitedate():$visitelast);
|
||||
$visitecpt = 0;
|
||||
$visitelast = null;
|
||||
foreach ($data->getUsers() as $usergroup) {
|
||||
$visitecpt += intval($usergroup->getVisitecpt());
|
||||
$visitelast = ($usergroup->getVisitedate() > $visitelast ? $usergroup->getVisitedate() : $visitelast);
|
||||
}
|
||||
|
||||
$tmp=array();
|
||||
array_push($tmp,$action);
|
||||
array_push($tmp,$data->getLabel());
|
||||
array_push($tmp,($data->isIsworkgroup()?"oui":"non"));
|
||||
array_push($tmp,($data->isIsopen()?"oui":"non"));
|
||||
array_push($tmp,$userinfo);
|
||||
array_push($tmp,($visitelast?$visitelast->format("d/m/Y H:i")."<br>":"")."nb = ".$visitecpt);
|
||||
array_push($output["data"],$tmp);
|
||||
$tmp = [];
|
||||
array_push($tmp, $action);
|
||||
array_push($tmp, $data->getLabel());
|
||||
array_push($tmp, $data->isIsworkgroup() ? 'oui' : 'non');
|
||||
array_push($tmp, $data->isIsopen() ? 'oui' : 'non');
|
||||
array_push($tmp, $userinfo);
|
||||
array_push($tmp, ($visitelast ? $visitelast->format('d/m/Y H:i').'<br>' : '').'nb = '.$visitecpt);
|
||||
array_push($output['data'], $tmp);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function submit($access,Request $request,ManagerRegistry $em): Response
|
||||
public function submit($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data = new Entity();
|
||||
$data->setApikey(Uuid::uuid4());
|
||||
if($access=="user") {
|
||||
if ('user' == $access) {
|
||||
$data->setOwner($this->getUser());
|
||||
$data->setIsworkgroup(true);
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->cansubmit($access,$em);
|
||||
$this->cansubmit($access, $em);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"submit",
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"access"=>$access,
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'submit',
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'access' => $access,
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// Les groupes opé ne sont pas ouvert
|
||||
if(!$data->isIsworkgroup()) $data->setIsopen(false);
|
||||
if (!$data->isIsworkgroup()) {
|
||||
$data->setIsopen(false);
|
||||
}
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->persist($data);
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>($access!="user"),
|
||||
"mode"=>"submit",
|
||||
"access"=>$access,
|
||||
"form"=>$form->createView(),
|
||||
$this->data=>$data,
|
||||
"maxsize"=>($access=="user"?1200:null),
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => ('user' != $access),
|
||||
'mode' => 'submit',
|
||||
'access' => $access,
|
||||
'form' => $form->createView(),
|
||||
$this->data => $data,
|
||||
'maxsize' => ('user' == $access ? 1200 : null),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function update($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data or $id<0) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data or $id < 0) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->canupdate($access,$data,$em);
|
||||
$this->canupdate($access, $data, $em);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"update",
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"access"=>$access,
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'update',
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'access' => $access,
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// Les groupes opé ne sont pas ouvert
|
||||
if(!$data->isIsworkgroup()) $data->setIsopen(false);
|
||||
if (!$data->isIsworkgroup()) {
|
||||
$data->setIsopen(false);
|
||||
}
|
||||
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
"useheader" => true,
|
||||
"usemenu" => false,
|
||||
"usesidebar" => ($access!="user"),
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => ('user' != $access),
|
||||
$this->data => $data,
|
||||
"mode" => "update",
|
||||
"access"=>$access,
|
||||
"form" => $form->createView(),
|
||||
"maxsize"=>($access=="user"?1200:null),
|
||||
'mode' => 'update',
|
||||
'access' => $access,
|
||||
'form' => $form->createView(),
|
||||
'maxsize' => ('user' == $access ? 1200 : null),
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function delete($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->canupdate($access,$data,$em);
|
||||
$this->canupdate($access, $data, $em);
|
||||
|
||||
// Tentative de suppression
|
||||
try{
|
||||
try {
|
||||
$em->getManager()->remove($data);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add("error", $e->getMessage());
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route)."_update",["id"=>$id]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
|
||||
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function users($id,$access,Request $request,ManagerRegistry $em)
|
||||
{
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
public function users($id, $access, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->canseemember($access,$data,$em);
|
||||
|
||||
$this->canseemember($access, $data, $em);
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'users.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => ($access!="user"),
|
||||
'access' => $access,
|
||||
$this->data => $data,
|
||||
]);
|
||||
}
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => ('user' != $access),
|
||||
'access' => $access,
|
||||
$this->data => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
public function usersnotin($id,$access,Request $request,ManagerRegistry $em)
|
||||
public function usersnotin($id, $access, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$group=$em->getRepository($this->entity)->find($id);
|
||||
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$group = $em->getRepository($this->entity)->find($id);
|
||||
if (!$group) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->canseemember($access,$group,$em);
|
||||
$this->canseemember($access, $group, $em);
|
||||
|
||||
$sub = $em->getManager()->createQueryBuilder();
|
||||
$sub->select("usergroup");
|
||||
$sub->from("App:UserGroup","usergroup");
|
||||
$sub->select('usergroup');
|
||||
$sub->from('App:UserGroup', 'usergroup');
|
||||
$sub->andWhere('usergroup.user = user.id');
|
||||
$sub->andWhere('usergroup.group = :groupid');
|
||||
$sub->andWhere('usergroup.group = :groupid');
|
||||
|
||||
$query=$request->query->all();
|
||||
$start=$query['start'];
|
||||
$length=$query['length'];
|
||||
$search=$query['search'];
|
||||
$draw= $query['draw'];
|
||||
$ordercolumn=$query['order'][0]['column'];
|
||||
$orderdir=$query['order'][0]['dir'];
|
||||
$usermodo=null;
|
||||
$niveau01=null;
|
||||
$niveau02=null;
|
||||
$query = $request->query->all();
|
||||
$start = $query['start'];
|
||||
$length = $query['length'];
|
||||
$search = $query['search'];
|
||||
$draw = $query['draw'];
|
||||
$ordercolumn = $query['order'][0]['column'];
|
||||
$orderdir = $query['order'][0]['dir'];
|
||||
$usermodo = null;
|
||||
$niveau01 = null;
|
||||
$niveau02 = null;
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
switch($access) {
|
||||
case "admin":
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$qb->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->from('App:User', 'user')
|
||||
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->setParameter("groupid",$id);
|
||||
break;
|
||||
|
||||
case "modo":
|
||||
$usermodo=$this->getUser()->getId();
|
||||
$qb->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->from('App:UserModo','usermodo')
|
||||
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->andWhere("usermodo.niveau01 = user.niveau01")
|
||||
->andWhere("usermodo.user = :userid")
|
||||
->setParameter("userid", $usermodo)
|
||||
->setParameter("groupid",$id);
|
||||
break;
|
||||
|
||||
case "user":
|
||||
$niveau01=$this->getUser()->getNiveau01();
|
||||
$niveau02=$this->getUser()->getNiveau02();
|
||||
|
||||
$qb->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->setParameter("groupid",$id);
|
||||
|
||||
switch($request->getSession()->get("scopeannu")) {
|
||||
case "SAME_NIVEAU01":
|
||||
$qb->andWhere("user.niveau01 = :niveau01")->setParameter("niveau01",$niveau01);
|
||||
break;
|
||||
|
||||
case "SAME_NIVEAU02":
|
||||
$qb->andWhere("user.niveau02 = :niveau02")->setParameter("niveau02",$niveau02);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$total=$qb->getQuery()->getSingleScalarResult();
|
||||
$totalf=null;
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if($search["value"]=="")
|
||||
$totalf = $total;
|
||||
else {
|
||||
switch($access) {
|
||||
case "admin":
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->where('user.username LIKE :value OR user.email LIKE :value')
|
||||
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter("groupid",$id)
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
->setParameter('groupid', $id);
|
||||
break;
|
||||
|
||||
case "modo":
|
||||
case 'modo':
|
||||
$usermodo = $this->getUser()->getId();
|
||||
$qb->select('COUNT(user)')
|
||||
->from('App:User', 'user')
|
||||
->from('App:UserModo', 'usermodo')
|
||||
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->andWhere('usermodo.niveau01 = user.niveau01')
|
||||
->andWhere('usermodo.user = :userid')
|
||||
->setParameter('userid', $usermodo)
|
||||
->setParameter('groupid', $id);
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
$niveau01 = $this->getUser()->getNiveau01();
|
||||
$niveau02 = $this->getUser()->getNiveau02();
|
||||
|
||||
$qb->select('COUNT(user)')
|
||||
->from('App:User', 'user')
|
||||
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->setParameter('groupid', $id);
|
||||
|
||||
switch ($request->getSession()->get('scopeannu')) {
|
||||
case 'SAME_NIVEAU01':
|
||||
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
|
||||
break;
|
||||
|
||||
case 'SAME_NIVEAU02':
|
||||
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$total = $qb->getQuery()->getSingleScalarResult();
|
||||
$totalf = null;
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if ('' == $search['value']) {
|
||||
$totalf = $total;
|
||||
} else {
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->from('App:UserModo','usermodo')
|
||||
->from('App:User', 'user')
|
||||
->where('user.username LIKE :value OR user.email LIKE :value')
|
||||
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->andWhere("usermodo.niveau01 = user.niveau01")
|
||||
->andWhere("usermodo.user = :userid")
|
||||
->setParameter("userid", $usermodo)
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter("groupid",$id)
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->setParameter('groupid', $id)
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
break;
|
||||
break;
|
||||
|
||||
case "user":
|
||||
case 'modo':
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(user)')
|
||||
->from('App:User', 'user')
|
||||
->from('App:UserModo', 'usermodo')
|
||||
->where('user.username LIKE :value OR user.email LIKE :value')
|
||||
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->andWhere('usermodo.niveau01 = user.niveau01')
|
||||
->andWhere('usermodo.user = :userid')
|
||||
->setParameter('userid', $usermodo)
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->setParameter('groupid', $id)
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
$qb = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->from('App:User', 'user')
|
||||
->where('user.username LIKE :value OR user.email LIKE :value')
|
||||
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter("groupid",$id);
|
||||
|
||||
switch($request->getSession()->get("scopeannu")) {
|
||||
case "SAME_NIVEAU01":
|
||||
$qb->andWhere("user.niveau01 = :niveau01")->setParameter("niveau01",$niveau01);
|
||||
break;
|
||||
|
||||
case "SAME_NIVEAU02":
|
||||
$qb->andWhere("user.niveau02 = :niveau02")->setParameter("niveau02",$niveau02);
|
||||
break;
|
||||
}
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->setParameter('groupid', $id);
|
||||
|
||||
$totalf=$qb->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
switch ($request->getSession()->get('scopeannu')) {
|
||||
case 'SAME_NIVEAU01':
|
||||
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
|
||||
break;
|
||||
|
||||
case 'SAME_NIVEAU02':
|
||||
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
|
||||
break;
|
||||
}
|
||||
|
||||
$totalf = $qb->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('user')->from("App:User",'user');
|
||||
|
||||
switch($access) {
|
||||
case "admin":
|
||||
$qb->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
|
||||
break;
|
||||
$qb->select('user')->from('App:User', 'user');
|
||||
|
||||
case "modo":
|
||||
$qb->from('App:UserModo','usermodo')
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$qb->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
|
||||
break;
|
||||
|
||||
case 'modo':
|
||||
$qb->from('App:UserModo', 'usermodo')
|
||||
->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
|
||||
->andWhere("usermodo.niveau01 = user.niveau01")
|
||||
->andWhere("usermodo.user = :userid")
|
||||
->setParameter("userid", $usermodo);
|
||||
break;
|
||||
->andWhere('usermodo.niveau01 = user.niveau01')
|
||||
->andWhere('usermodo.user = :userid')
|
||||
->setParameter('userid', $usermodo);
|
||||
break;
|
||||
|
||||
case "user":
|
||||
case 'user':
|
||||
$qb->where($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
|
||||
switch($request->getSession()->get("scopeannu")) {
|
||||
case "SAME_NIVEAU01":
|
||||
$qb->andWhere("user.niveau01 = :niveau01")->setParameter("niveau01",$niveau01);
|
||||
break;
|
||||
switch ($request->getSession()->get('scopeannu')) {
|
||||
case 'SAME_NIVEAU01':
|
||||
$qb->andWhere('user.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
|
||||
break;
|
||||
|
||||
case "SAME_NIVEAU02":
|
||||
$qb->andWhere("user.niveau02 = :niveau02")->setParameter("niveau02",$niveau02);
|
||||
break;
|
||||
case 'SAME_NIVEAU02':
|
||||
$qb->andWhere('user.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if($search["value"]!="") {
|
||||
$qb ->andWhere('user.username LIKE :value OR user.email LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
if ('' != $search['value']) {
|
||||
$qb->andWhere('user.username LIKE :value OR user.email LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
$qb->setParameter("groupid",$id);
|
||||
switch($ordercolumn) {
|
||||
case 2 :
|
||||
$qb->orderBy('user.username',$orderdir);
|
||||
break;
|
||||
$qb->setParameter('groupid', $id);
|
||||
switch ($ordercolumn) {
|
||||
case 2:
|
||||
$qb->orderBy('user.username', $orderdir);
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
$qb->orderBy('user.email',$orderdir);
|
||||
break;
|
||||
case 3:
|
||||
$qb->orderBy('user.email', $orderdir);
|
||||
break;
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$canupdatemember=$this->canupdatemember($access,$group,$em,false);
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$canupdatemember = $this->canupdatemember($access, $group, $em, false);
|
||||
|
||||
foreach($datas as $data) {
|
||||
foreach ($datas as $data) {
|
||||
// Action
|
||||
$action = "";
|
||||
if($canupdatemember)
|
||||
$action.="<a style='cursor:pointer' onClick='addUsers(".$data->getId().")'><i class='fa fa-plus fa-fw'></i></a>";
|
||||
|
||||
// Avatar
|
||||
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>";
|
||||
$action = '';
|
||||
if ($canupdatemember) {
|
||||
$action .= "<a style='cursor:pointer' onClick='addUsers(".$data->getId().")'><i class='fa fa-plus fa-fw'></i></a>";
|
||||
}
|
||||
|
||||
array_push($output["data"],array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),"",""));
|
||||
// Avatar
|
||||
$avatar = "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getAvatar()])."' class='avatar'>";
|
||||
|
||||
array_push($output['data'], ['DT_RowId' => 'user'.$data->getId(), $action, $avatar, $data->getUsername(), $data->getEmail(), '', '']);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function usersin($id,$access,Request $request,ManagerRegistry $em)
|
||||
{
|
||||
public function usersin($id, $access, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$group=$em->getRepository($this->entity)->find($id);
|
||||
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$group = $em->getRepository($this->entity)->find($id);
|
||||
if (!$group) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->canseemember($access,$group,$em);
|
||||
$this->canseemember($access, $group, $em);
|
||||
|
||||
$sub = $em->getManager()->createQueryBuilder();
|
||||
$sub->select("usergroup");
|
||||
$sub->from("App:UserGroup","usergroup");
|
||||
$sub->select('usergroup');
|
||||
$sub->from('App:UserGroup', 'usergroup');
|
||||
$sub->andWhere('usergroup.user = user.id');
|
||||
$sub->andWhere('usergroup.group = :groupid');
|
||||
$sub->andWhere('usergroup.group = :groupid');
|
||||
|
||||
$query=$request->query->all();
|
||||
$start=$query['start'];
|
||||
$length=$query['length'];
|
||||
$search=$query['search'];
|
||||
$draw= $query['draw'];
|
||||
$ordercolumn=$query['order'][0]['column'];
|
||||
$orderdir=$query['order'][0]['dir'];
|
||||
$usermodo=null;
|
||||
$query = $request->query->all();
|
||||
$start = $query['start'];
|
||||
$length = $query['length'];
|
||||
$search = $query['search'];
|
||||
$draw = $query['draw'];
|
||||
$ordercolumn = $query['order'][0]['column'];
|
||||
$orderdir = $query['order'][0]['dir'];
|
||||
$usermodo = null;
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
if($access=="admin"||$access=="user")
|
||||
if ('admin' == $access || 'user' == $access) {
|
||||
$qb->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->from('App:User', 'user')
|
||||
->where($qb->expr()->exists($sub->getDQL()))
|
||||
->setParameter("groupid",$id);
|
||||
else {
|
||||
$usermodo=$this->getUser()->getId();
|
||||
->setParameter('groupid', $id);
|
||||
} else {
|
||||
$usermodo = $this->getUser()->getId();
|
||||
$qb->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->from('App:UserModo','usermodo')
|
||||
->from('App:User', 'user')
|
||||
->from('App:UserModo', 'usermodo')
|
||||
->where($qb->expr()->exists($sub->getDQL()))
|
||||
->andWhere("usermodo.niveau01 = user.niveau01")
|
||||
->andWhere("usermodo.user = :userid")
|
||||
->setParameter("userid", $usermodo)
|
||||
->setParameter("groupid",$id);
|
||||
->andWhere('usermodo.niveau01 = user.niveau01')
|
||||
->andWhere('usermodo.user = :userid')
|
||||
->setParameter('userid', $usermodo)
|
||||
->setParameter('groupid', $id);
|
||||
}
|
||||
$total=$qb->getQuery()->getSingleScalarResult();
|
||||
$total = $qb->getQuery()->getSingleScalarResult();
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if($search["value"]=="")
|
||||
if ('' == $search['value']) {
|
||||
$totalf = $total;
|
||||
else {
|
||||
if($access=="admin"||$access=="user")
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
if ('admin' == $access || 'user' == $access) {
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->from('App:User', 'user')
|
||||
->where('user.username LIKE :value OR user.email LIKE :value')
|
||||
->andWhere($qb->expr()->exists($sub->getDQL()))
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter("groupid",$id)
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->setParameter('groupid', $id)
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
else
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(user)')
|
||||
->from('App:User','user')
|
||||
->from('App:UserModo','usermodo')
|
||||
->from('App:User', 'user')
|
||||
->from('App:UserModo', 'usermodo')
|
||||
->where('user.username LIKE :value OR user.email LIKE :value')
|
||||
->andWhere($qb->expr()->exists($sub->getDQL()))
|
||||
->andWhere("usermodo.niveau01 = user.niveau01")
|
||||
->andWhere("usermodo.user = :userid")
|
||||
->setParameter("userid", $usermodo)
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter("groupid",$id)
|
||||
->andWhere('usermodo.niveau01 = user.niveau01')
|
||||
->andWhere('usermodo.user = :userid')
|
||||
->setParameter('userid', $usermodo)
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->setParameter('groupid', $id)
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('user')->from("App:User",'user');
|
||||
|
||||
if($access=="admin"||$access=="user")
|
||||
$qb->select('user')->from('App:User', 'user');
|
||||
|
||||
if ('admin' == $access || 'user' == $access) {
|
||||
$qb->where($qb->expr()->exists($sub->getDQL()));
|
||||
else
|
||||
$qb->from('App:UserModo','usermodo')
|
||||
} else {
|
||||
$qb->from('App:UserModo', 'usermodo')
|
||||
->where($qb->expr()->exists($sub->getDQL()))
|
||||
->andWhere("usermodo.niveau01 = user.niveau01")
|
||||
->andWhere("usermodo.user = :userid")
|
||||
->setParameter("userid", $usermodo);
|
||||
|
||||
if($search["value"]!="") {
|
||||
$qb ->andWhere('user.username LIKE :value OR user.email LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
}
|
||||
$qb->setParameter("groupid",$id);
|
||||
switch($ordercolumn) {
|
||||
case 2 :
|
||||
$qb->orderBy('user.username',$orderdir);
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
$qb->orderBy('user.email',$orderdir);
|
||||
break;
|
||||
->andWhere('usermodo.niveau01 = user.niveau01')
|
||||
->andWhere('usermodo.user = :userid')
|
||||
->setParameter('userid', $usermodo);
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach($datas as $data) {
|
||||
if ('' != $search['value']) {
|
||||
$qb->andWhere('user.username LIKE :value OR user.email LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
$qb->setParameter('groupid', $id);
|
||||
switch ($ordercolumn) {
|
||||
case 2:
|
||||
$qb->orderBy('user.username', $orderdir);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$qb->orderBy('user.email', $orderdir);
|
||||
break;
|
||||
}
|
||||
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach ($datas as $data) {
|
||||
// Propriétaire
|
||||
$usergroup=$em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$data->getId(),"group"=>$id]);
|
||||
$fgproprio=($usergroup->getUser()==$group->getOwner());
|
||||
$fgme=($usergroup->getUser()==$this->getUser()&&$access!="admin");
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $data->getId(), 'group' => $id]);
|
||||
$fgproprio = ($usergroup->getUser() == $group->getOwner());
|
||||
$fgme = ($usergroup->getUser() == $this->getUser() && 'admin' != $access);
|
||||
|
||||
// Action
|
||||
$action = "";
|
||||
if($this->canupdatemember($access,$group,$em,false)&&!$fgproprio&&!$fgme)
|
||||
$action.="<a style='cursor:pointer' onClick='delUsers(".$data->getId().")'><i class='fa fa-minus fa-fw'></i></a>";
|
||||
$action = '';
|
||||
if ($this->canupdatemember($access, $group, $em, false) && !$fgproprio && !$fgme) {
|
||||
$action .= "<a style='cursor:pointer' onClick='delUsers(".$data->getId().")'><i class='fa fa-minus fa-fw'></i></a>";
|
||||
}
|
||||
|
||||
// Avatar
|
||||
$avatar="<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>";
|
||||
$avatar = "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getAvatar()])."' class='avatar'>";
|
||||
|
||||
// Flag manager
|
||||
$rolegroup="";
|
||||
if($fgproprio) $rolegroup="Propriétaire du groupe";
|
||||
elseif($this->canupdatemember($access,$group,$em,false)&&!$fgme) {
|
||||
$selectuser=($usergroup->getRolegroup()==0?"selected='selected'":"");
|
||||
$selectwritter=($usergroup->getRolegroup()==50?"selected='selected'":"");
|
||||
$selectmanager=($usergroup->getRolegroup()==90?"selected='selected'":"");
|
||||
$rolegroup = '';
|
||||
if ($fgproprio) {
|
||||
$rolegroup = 'Propriétaire du groupe';
|
||||
} elseif ($this->canupdatemember($access, $group, $em, false) && !$fgme) {
|
||||
$selectuser = (0 == $usergroup->getRolegroup() ? "selected='selected'" : '');
|
||||
$selectwritter = (50 == $usergroup->getRolegroup() ? "selected='selected'" : '');
|
||||
$selectmanager = (90 == $usergroup->getRolegroup() ? "selected='selected'" : '');
|
||||
|
||||
$rolegroup='<select id="roleuser-'.$data->getId().'" name="user[visible]" onChange="changeRole('.$data->getId().');"><option value="0" '.$selectuser.'>Utilisateur</option><option value="50" '.$selectwritter.'>Collaborateur</option><option value="90" '.$selectmanager.'>Gestionnaire</option></select>';
|
||||
$rolegroup = '<select id="roleuser-'.$data->getId().'" name="user[visible]" onChange="changeRole('.$data->getId().');"><option value="0" '.$selectuser.'>Utilisateur</option><option value="50" '.$selectwritter.'>Collaborateur</option><option value="90" '.$selectmanager.'>Gestionnaire</option></select>';
|
||||
} else {
|
||||
$rolegroup = (0 == $usergroup->getRolegroup() ? 'Utilisateur' : (50 == $usergroup->getRolegroup() ? 'Collaborateur' : 'Gestionnaire'));
|
||||
}
|
||||
else $rolegroup=($usergroup->getRolegroup()==0?"Utilisateur":($usergroup->getRolegroup()==50?"Collaborateur":"Gestionnaire"));
|
||||
|
||||
$tmp=array("DT_RowId"=>"user".$data->getId(),$action,$avatar,$data->getUsername(),$data->getEmail(),$rolegroup);
|
||||
array_push($output["data"],$tmp);
|
||||
|
||||
$tmp = ['DT_RowId' => 'user'.$data->getId(), $action, $avatar, $data->getUsername(), $data->getEmail(), $rolegroup];
|
||||
array_push($output['data'], $tmp);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
}
|
||||
|
||||
public function useradd($groupid,$userid,$access,Request $request,ManagerRegistry $em)
|
||||
public function useradd($groupid, $userid, $access, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$group=$em->getRepository($this->entity)->find($groupid);
|
||||
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$group = $em->getRepository($this->entity)->find($groupid);
|
||||
if (!$group) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
$user=$em->getRepository("App\Entity\User")->find($userid);
|
||||
if (!$user) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$user = $em->getRepository("App\Entity\User")->find($userid);
|
||||
if (!$user) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$this->canupdatemember($access,$group,$em,true);
|
||||
$output = [];
|
||||
$this->canupdatemember($access, $group, $em, true);
|
||||
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(array("user"=>$user,"group"=>$group));
|
||||
if($usergroup) return new JsonResponse($output);
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
||||
if ($usergroup) {
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
|
||||
$usergroup=new UserGroup();
|
||||
$usergroup = new UserGroup();
|
||||
$usergroup->setUser($user);
|
||||
$usergroup->setGroup($group);
|
||||
$usergroup->setApikey(Uuid::uuid4());
|
||||
@ -697,127 +722,168 @@ class GroupController extends AbstractController
|
||||
$em->getManager()->persist($usergroup);
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
|
||||
public function userdel($groupid,$userid,$access,Request $request,ManagerRegistry $em)
|
||||
public function userdel($groupid, $userid, $access, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$group=$em->getRepository($this->entity)->find($groupid);
|
||||
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$group = $em->getRepository($this->entity)->find($groupid);
|
||||
if (!$group) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
$user=$em->getRepository("App\Entity\User")->find($userid);
|
||||
if (!$user) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$user = $em->getRepository("App\Entity\User")->find($userid);
|
||||
if (!$user) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$this->canupdatemember($access,$group,$em,true);
|
||||
if($user==$group->getOwner()) throw $this->createAccessDeniedException('Permission denied');
|
||||
$output = [];
|
||||
$this->canupdatemember($access, $group, $em, true);
|
||||
if ($user == $group->getOwner()) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(array("user"=>$user,"group"=>$group));
|
||||
if($usergroup) {
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
||||
if ($usergroup) {
|
||||
$em->getManager()->remove($usergroup);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
|
||||
// Retour
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
|
||||
public function userchangerole($groupid,$userid,$roleid,$access,Request $request,ManagerRegistry $em)
|
||||
public function userchangerole($groupid, $userid, $roleid, $access, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$group=$em->getRepository($this->entity)->find($groupid);
|
||||
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$group = $em->getRepository($this->entity)->find($groupid);
|
||||
if (!$group) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
$user=$em->getRepository("App\Entity\User")->find($userid);
|
||||
if (!$user) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$user = $em->getRepository("App\Entity\User")->find($userid);
|
||||
if (!$user) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
$output=array();
|
||||
$this->canupdatemember($access,$group,$em,true);
|
||||
if($user==$group->getOwner()) throw $this->createAccessDeniedException('Permission denied');
|
||||
|
||||
$output = [];
|
||||
$this->canupdatemember($access, $group, $em, true);
|
||||
if ($user == $group->getOwner()) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(array("user"=>$user,"group"=>$group));
|
||||
if($usergroup) {
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $user, 'group' => $group]);
|
||||
if ($usergroup) {
|
||||
$usergroup->setRolegroup($roleid);
|
||||
$em->getManager()->persist($usergroup);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
|
||||
// Retour
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
|
||||
public function userout($id,$access,Request $request,ManagerRegistry $em)
|
||||
public function userout($id, $access, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$group=$em->getRepository($this->entity)->find($id);
|
||||
if (!$group) throw $this->createNotFoundException('Unable to find entity.');
|
||||
|
||||
// On ne peut se désinscrire que si le groupe est ouvert et qu'il n'est pas lié à un groupe ldap ou sso
|
||||
if($group->getOwner()!=$this->getUser()&&($group->isIsOpen()||$this->canupdatemember($access,$group,$em,false))) {
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(array("user"=>$this->getUser(),"group"=>$group));
|
||||
if($usergroup) {
|
||||
$em->getManager()->remove($usergroup);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
$group = $em->getRepository($this->entity)->find($id);
|
||||
if (!$group) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
// On ne peut se désinscrire que si le groupe est ouvert et qu'il n'est pas lié à un groupe ldap ou sso
|
||||
if ($group->getOwner() != $this->getUser() && ($group->isIsOpen() || $this->canupdatemember($access, $group, $em, false))) {
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $this->getUser(), 'group' => $group]);
|
||||
if ($usergroup) {
|
||||
$em->getManager()->remove($usergroup);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
private function cansubmit($access,$em) {
|
||||
switch($access) {
|
||||
case "admin" : return true; break;
|
||||
case "user" : return true; break;
|
||||
private function cansubmit($access, $em)
|
||||
{
|
||||
switch ($access) {
|
||||
case 'admin': return true;
|
||||
break;
|
||||
case 'user': return true;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
|
||||
private function canupdate($access,$entity,$em,$fgblock=true) {
|
||||
$toreturn=false;
|
||||
switch($access) {
|
||||
case "admin" : $toreturn=($entity->getId()>0); break;
|
||||
case "user":
|
||||
if(!$entity->isIsworkgroup()||$entity->getOwner()!=$this->getUser()) $toreturn=false;
|
||||
else $toreturn=true;
|
||||
break;
|
||||
private function canupdate($access, $entity, $em, $fgblock = true)
|
||||
{
|
||||
$toreturn = false;
|
||||
switch ($access) {
|
||||
case 'admin': $toreturn = ($entity->getId() > 0);
|
||||
break;
|
||||
case 'user':
|
||||
if (!$entity->isIsworkgroup() || $entity->getOwner() != $this->getUser()) {
|
||||
$toreturn = false;
|
||||
} else {
|
||||
$toreturn = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if($fgblock&&!$toreturn) throw $this->createAccessDeniedException('Permission denied');
|
||||
if ($fgblock && !$toreturn) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return $toreturn;
|
||||
}
|
||||
|
||||
private function canseemember($access,$entity,$em,$fgblock=true) {
|
||||
$toreturn=false;
|
||||
switch($access) {
|
||||
case "admin" : $toreturn=($entity->getId()>0); break;
|
||||
case "modo" : $toreturn=($entity->getId()>0); break;
|
||||
case "user":
|
||||
$usergroup=$em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$this->getUser(),"group"=>$entity]);
|
||||
if(!$usergroup||!$entity->isIsworkgroup()||$entity->getId()<0) $toreturn=false;
|
||||
else $toreturn=true;
|
||||
break;
|
||||
private function canseemember($access, $entity, $em, $fgblock = true)
|
||||
{
|
||||
$toreturn = false;
|
||||
switch ($access) {
|
||||
case 'admin': $toreturn = ($entity->getId() > 0);
|
||||
break;
|
||||
case 'modo': $toreturn = ($entity->getId() > 0);
|
||||
break;
|
||||
case 'user':
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $this->getUser(), 'group' => $entity]);
|
||||
if (!$usergroup || !$entity->isIsworkgroup() || $entity->getId() < 0) {
|
||||
$toreturn = false;
|
||||
} else {
|
||||
$toreturn = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if($fgblock&&!$toreturn) throw $this->createAccessDeniedException('Permission denied');
|
||||
if ($fgblock && !$toreturn) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return $toreturn;
|
||||
}
|
||||
|
||||
|
||||
private function canupdatemember($access,$entity,$em,$fgblock=true) {
|
||||
$toreturn=false;
|
||||
switch($access) {
|
||||
case "admin" : $toreturn=($entity->getId()>0&&!$entity->getLdapfilter()); break;
|
||||
case "modo" : $toreturn=($entity->getId()>0); break;
|
||||
case "user":
|
||||
$usergroup=$em->getRepository("App\Entity\UserGroup")->findOneBy(["user"=>$this->getUser(),"group"=>$entity]);
|
||||
if(!$usergroup||!$entity->isIsworkgroup()||$entity->getId()<0) $toreturn=false;
|
||||
elseif($usergroup->getRolegroup()<90) $toreturn=false;
|
||||
else $toreturn=true;
|
||||
break;
|
||||
private function canupdatemember($access, $entity, $em, $fgblock = true)
|
||||
{
|
||||
$toreturn = false;
|
||||
switch ($access) {
|
||||
case 'admin': $toreturn = ($entity->getId() > 0 && !$entity->getLdapfilter());
|
||||
break;
|
||||
case 'modo': $toreturn = ($entity->getId() > 0);
|
||||
break;
|
||||
case 'user':
|
||||
$usergroup = $em->getRepository("App\Entity\UserGroup")->findOneBy(['user' => $this->getUser(), 'group' => $entity]);
|
||||
if (!$usergroup || !$entity->isIsworkgroup() || $entity->getId() < 0) {
|
||||
$toreturn = false;
|
||||
} elseif ($usergroup->getRolegroup() < 90) {
|
||||
$toreturn = false;
|
||||
} else {
|
||||
$toreturn = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if($fgblock&&!$toreturn) throw $this->createAccessDeniedException('Permission denied');
|
||||
if ($fgblock && !$toreturn) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return $toreturn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
public function home(Request $request): Response
|
||||
{
|
||||
if($request->getSession()->get("fgforceconnect"))
|
||||
return $this->redirectToRoute("app_user_home");
|
||||
{
|
||||
if ($request->getSession()->get('fgforceconnect')) {
|
||||
return $this->redirectToRoute('app_user_home');
|
||||
}
|
||||
|
||||
return $this->render('Home/home.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>true,
|
||||
"usesidebar"=>false,
|
||||
"maxsize"=>1000,
|
||||
return $this->render('Home/home.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => true,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1000,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function homeuser($access): Response
|
||||
{
|
||||
return $this->render('Home/home.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>false,
|
||||
"maxsize"=>1000,
|
||||
{
|
||||
return $this->render('Home/home.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1000,
|
||||
]);
|
||||
}
|
||||
|
||||
public function homeadmin($access): Response
|
||||
{
|
||||
return $this->redirectToRoute("app_admin_config");
|
||||
{
|
||||
return $this->redirectToRoute('app_admin_config');
|
||||
}
|
||||
|
||||
|
||||
public function homemodo($access): Response
|
||||
{
|
||||
return $this->redirectToRoute("app_modo_niveau02");
|
||||
{
|
||||
return $this->redirectToRoute('app_modo_niveau02');
|
||||
}
|
||||
|
||||
public function docrest(): Response
|
||||
{
|
||||
return $this->render('Home/docrest.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
{
|
||||
return $this->render('Home/docrest.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Form\LoginType;
|
||||
use App\Service\ApiService;
|
||||
use App\Service\LdapService;
|
||||
use App\Service\PasswordEncoder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use App\Service\ApiService;
|
||||
use App\Service\PasswordEncoder;
|
||||
use App\Service\LdapService;
|
||||
|
||||
use App\Form\LoginType;
|
||||
|
||||
|
||||
class HydraController extends AbstractController
|
||||
{
|
||||
|
||||
private $apiservice;
|
||||
private $passwordencoder;
|
||||
private $ldapservice;
|
||||
|
||||
public function __construct(ApiService $apiservice,LdapService $ldapservice,PasswordEncoder $passwordencoder)
|
||||
public function __construct(ApiService $apiservice, LdapService $ldapservice, PasswordEncoder $passwordencoder)
|
||||
{
|
||||
$this->apiservice = $apiservice;
|
||||
$this->passwordencoder = $passwordencoder;
|
||||
@ -29,19 +26,19 @@ class HydraController extends AbstractController
|
||||
}
|
||||
|
||||
public function loginsql(Request $request): Response
|
||||
{
|
||||
|
||||
{
|
||||
$challenge = $request->query->get('login_challenge');
|
||||
|
||||
// S'il n'y a pas de challenge, on déclenche une bad request
|
||||
if (!$challenge) {
|
||||
throw new BadRequestException('pas de challenge');
|
||||
}
|
||||
|
||||
|
||||
// On vérifie que la requête d'identification provient bien de hydra
|
||||
$response = $this->apiservice->run("GET",$this->getParameter('hydraLoginchallenge').$challenge,null);
|
||||
if(!$response)
|
||||
$response = $this->apiservice->run('GET', $this->getParameter('hydraLoginchallenge').$challenge, null);
|
||||
if (!$response) {
|
||||
throw new BadRequestException('challenge invalide');
|
||||
}
|
||||
|
||||
// si le challenge est validé par hydra, on le stocke en session pour l'utiliser par la suite et on redirige vers une route interne protégée qui va déclencher l'identification FranceConnect
|
||||
$request->getSession()->set('hydraChallenge', $challenge);
|
||||
@ -51,60 +48,65 @@ class HydraController extends AbstractController
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render("Home/loginHYDRA.html.twig", [
|
||||
"useheader"=>false,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>false,
|
||||
"form"=>$form->createView(),
|
||||
"mode"=>"SQL",
|
||||
return $this->render('Home/loginHYDRA.html.twig', [
|
||||
'useheader' => false,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'form' => $form->createView(),
|
||||
'mode' => 'SQL',
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkloginsql(Request $request,ManagerRegistry $em) {
|
||||
$username=$request->get('login')["username"];
|
||||
$password=$request->get('login')["password"];
|
||||
public function checkloginsql(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
$username = $request->get('login')['username'];
|
||||
$password = $request->get('login')['password'];
|
||||
|
||||
// user exist ?
|
||||
$user=$em->getRepository("App\Entity\User")->findOneBy(["username"=>$username]);
|
||||
if(!$user) return $this->redirect($this->generateUrl('app_hydra_loginsql',["login_challenge"=>$request->getSession()->get("hydraChallenge")]));
|
||||
$user = $em->getRepository("App\Entity\User")->findOneBy(['username' => $username]);
|
||||
if (!$user) {
|
||||
return $this->redirect($this->generateUrl('app_hydra_loginsql', ['login_challenge' => $request->getSession()->get('hydraChallenge')]));
|
||||
}
|
||||
|
||||
$islogin=$this->passwordencoder->verify($user->getPassword(),$password,$user->getSalt());
|
||||
if(!$islogin) return $this->redirect($this->generateUrl('app_hydra_loginsql',["login_challenge"=>$request->getSession()->get("hydraChallenge")]));
|
||||
$islogin = $this->passwordencoder->verify($user->getPassword(), $password, $user->getSalt());
|
||||
if (!$islogin) {
|
||||
return $this->redirect($this->generateUrl('app_hydra_loginsql', ['login_challenge' => $request->getSession()->get('hydraChallenge')]));
|
||||
}
|
||||
|
||||
$response = $this->apiservice->run("PUT",$this->getParameter('hydraLoginchallengeaccept').$request->getSession()->get('hydraChallenge'),["subject"=>$user->getEmail(),"acr"=>"string"]);
|
||||
if(!$response||$response->code!="200")
|
||||
$response = $this->apiservice->run('PUT', $this->getParameter('hydraLoginchallengeaccept').$request->getSession()->get('hydraChallenge'), ['subject' => $user->getEmail(), 'acr' => 'string']);
|
||||
if (!$response || '200' != $response->code) {
|
||||
throw new BadRequestException('login accept invalide');
|
||||
}
|
||||
|
||||
$datas=[
|
||||
"username"=>$user->getUsername(),
|
||||
"email"=>$user->getEmail(),
|
||||
"firstname"=>$user->getFirstname(),
|
||||
"lastname"=>$user->getLastname()
|
||||
$datas = [
|
||||
'username' => $user->getUsername(),
|
||||
'email' => $user->getEmail(),
|
||||
'firstname' => $user->getFirstname(),
|
||||
'lastname' => $user->getLastname(),
|
||||
];
|
||||
$request->getSession()->set("datas",$datas);
|
||||
$request->getSession()->set('datas', $datas);
|
||||
|
||||
$redirect = $response->body->redirect_to;
|
||||
|
||||
$redirect=$response->body->redirect_to;
|
||||
return $this->redirect($redirect, 301);
|
||||
|
||||
}
|
||||
|
||||
public function loginldap(Request $request): Response
|
||||
{
|
||||
|
||||
{
|
||||
$challenge = $request->query->get('login_challenge');
|
||||
|
||||
// S'il n'y a pas de challenge, on déclenche une bad request
|
||||
if (!$challenge) {
|
||||
throw new BadRequestException('pas de challenge');
|
||||
}
|
||||
|
||||
|
||||
// On vérifie que la requête d'identification provient bien de hydra
|
||||
$response = $this->apiservice->run("GET",$this->getParameter('hydraLoginchallenge').$challenge,null);
|
||||
if(!$response)
|
||||
$response = $this->apiservice->run('GET', $this->getParameter('hydraLoginchallenge').$challenge, null);
|
||||
if (!$response) {
|
||||
throw new BadRequestException('challenge invalide');
|
||||
}
|
||||
|
||||
// si le challenge est validé par hydra, on le stocke en session pour l'utiliser par la suite et on redirige vers une route interne protégée qui va déclencher l'identification FranceConnect
|
||||
$request->getSession()->set('hydraChallenge', $challenge);
|
||||
@ -114,62 +116,66 @@ class HydraController extends AbstractController
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render("Home/loginHYDRA.html.twig", [
|
||||
"useheader"=>false,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>false,
|
||||
"form"=>$form->createView(),
|
||||
"mode"=>"LDAP",
|
||||
return $this->render('Home/loginHYDRA.html.twig', [
|
||||
'useheader' => false,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'form' => $form->createView(),
|
||||
'mode' => 'LDAP',
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkloginldap(Request $request,ManagerRegistry $em) {
|
||||
$username=$request->get('login')["username"];
|
||||
$password=$request->get('login')["password"];
|
||||
public function checkloginldap(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
$username = $request->get('login')['username'];
|
||||
$password = $request->get('login')['password'];
|
||||
|
||||
// L'utilisateur se co à l'annuaire ?
|
||||
$userldap=$this->ldapservice->userconnect($username,$password);
|
||||
if(!$userldap)
|
||||
return $this->redirect($this->generateUrl('app_hydra_loginldap',["login_challenge"=>$request->getSession()->get("hydraChallenge")]));
|
||||
$userldap = $this->ldapservice->userconnect($username, $password);
|
||||
if (!$userldap) {
|
||||
return $this->redirect($this->generateUrl('app_hydra_loginldap', ['login_challenge' => $request->getSession()->get('hydraChallenge')]));
|
||||
}
|
||||
|
||||
$userldap=$userldap[0];
|
||||
$userldap = $userldap[0];
|
||||
|
||||
// Init
|
||||
$email = "$username@nomail.fr";
|
||||
$lastname = $username;
|
||||
$firstname = " ";
|
||||
$firstname = ' ';
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
if(isset($userldap[$this->getParameter('ldapFirstname')]))
|
||||
if (isset($userldap[$this->getParameter('ldapFirstname')])) {
|
||||
$firstname = $userldap[$this->getParameter('ldapFirstname')];
|
||||
|
||||
if(isset($userldap[$this->getParameter('ldapLastname')]))
|
||||
}
|
||||
|
||||
if (isset($userldap[$this->getParameter('ldapLastname')])) {
|
||||
$lastname = $userldap[$this->getParameter('ldapLastname')];
|
||||
|
||||
if(isset($userldap[$this->getParameter('ldapEmail')]))
|
||||
}
|
||||
|
||||
if (isset($userldap[$this->getParameter('ldapEmail')])) {
|
||||
$email = $userldap[$this->getParameter('ldapEmail')];
|
||||
}
|
||||
|
||||
$response = $this->apiservice->run("PUT",$this->getParameter('hydraLoginchallengeaccept').$request->getSession()->get('hydraChallenge'),["subject"=>$email,"acr"=>"string"]);
|
||||
if(!$response||$response->code!="200")
|
||||
$response = $this->apiservice->run('PUT', $this->getParameter('hydraLoginchallengeaccept').$request->getSession()->get('hydraChallenge'), ['subject' => $email, 'acr' => 'string']);
|
||||
if (!$response || '200' != $response->code) {
|
||||
throw new BadRequestException('login accept invalide');
|
||||
}
|
||||
|
||||
$datas=[
|
||||
"username"=>$username,
|
||||
"email"=>$email,
|
||||
"firstname"=>$firstname,
|
||||
"lastname"=>$lastname
|
||||
$datas = [
|
||||
'username' => $username,
|
||||
'email' => $email,
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
];
|
||||
$request->getSession()->set("datas",$datas);
|
||||
$request->getSession()->set('datas', $datas);
|
||||
|
||||
$redirect = $response->body->redirect_to;
|
||||
|
||||
$redirect=$response->body->redirect_to;
|
||||
return $this->redirect($redirect, 301);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function consent(Request $request)
|
||||
{
|
||||
$challenge = $request->query->get('consent_challenge');
|
||||
@ -178,20 +184,22 @@ class HydraController extends AbstractController
|
||||
}
|
||||
|
||||
// On vérifie que la requête d'identification provient bien de hydra
|
||||
$response = $this->apiservice->run("GET",$this->getParameter('hydraConsentchallenge').$challenge,null);
|
||||
if(!$response)
|
||||
$response = $this->apiservice->run('GET', $this->getParameter('hydraConsentchallenge').$challenge, null);
|
||||
if (!$response) {
|
||||
throw new BadRequestException('challenge invalide');
|
||||
}
|
||||
|
||||
$response = $this->apiservice->run("PUT",$this->getParameter('hydraConsentchallengeaccept').$challenge,[
|
||||
$response = $this->apiservice->run('PUT', $this->getParameter('hydraConsentchallengeaccept').$challenge, [
|
||||
'grant_scope' => ['openid', 'offline_access'],
|
||||
'session' => ['id_token' => $request->getSession()->get('datas')]
|
||||
'session' => ['id_token' => $request->getSession()->get('datas')],
|
||||
]);
|
||||
|
||||
if(!$response)
|
||||
if (!$response) {
|
||||
throw new BadRequestException('challenge not accept');
|
||||
}
|
||||
|
||||
$redirect = $response->body->redirect_to;
|
||||
|
||||
$redirect=$response->body->redirect_to;
|
||||
return $this->redirect($redirect, 301);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\MinioService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Service\MinioService;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class MinioController extends AbstractController
|
||||
{
|
||||
@ -20,54 +20,54 @@ class MinioController extends AbstractController
|
||||
$this->minio = $minio;
|
||||
}
|
||||
|
||||
public function ckupload($access,Request $request): Response
|
||||
public function ckupload($access, Request $request): Response
|
||||
{
|
||||
// Fichier temporaire uploadé
|
||||
$tmpfile = $request->files->get('upload');
|
||||
$extention = $tmpfile->getClientOriginalExtension();
|
||||
$tmpfile = $request->files->get('upload');
|
||||
$extention = $tmpfile->getClientOriginalExtension();
|
||||
|
||||
// Répertoire de Destination
|
||||
$fs = new Filesystem();
|
||||
$rootdir = $this->getParameter('kernel.project_dir') . '/var/tmp';
|
||||
$fs->mkdir($rootdir."/ckeditor");
|
||||
|
||||
// Fichier cible
|
||||
$targetName = uniqid().".".$extention;
|
||||
$targetFile = "ckeditor/".$targetName;
|
||||
$targetUrl = $this->generateUrl('app_minio_document',["file"=>"ckeditor/".$targetName]);
|
||||
$fs = new Filesystem();
|
||||
$rootdir = $this->getParameter('kernel.project_dir').'/var/tmp';
|
||||
$fs->mkdir($rootdir.'/ckeditor');
|
||||
|
||||
//move_uploaded_file($tmpfile,$targetFile);
|
||||
$this->minio->upload($tmpfile,$targetFile,true);
|
||||
|
||||
$output["uploaded"]=1;
|
||||
$output["fileName"]=$targetName;
|
||||
$output["url"]=$targetUrl;
|
||||
// Fichier cible
|
||||
$targetName = uniqid().'.'.$extention;
|
||||
$targetFile = 'ckeditor/'.$targetName;
|
||||
$targetUrl = $this->generateUrl('app_minio_document', ['file' => 'ckeditor/'.$targetName]);
|
||||
|
||||
// move_uploaded_file($tmpfile,$targetFile);
|
||||
$this->minio->upload($tmpfile, $targetFile, true);
|
||||
|
||||
$output['uploaded'] = 1;
|
||||
$output['fileName'] = $targetName;
|
||||
$output['url'] = $targetUrl;
|
||||
|
||||
return new Response(json_encode($output));
|
||||
}
|
||||
|
||||
public function logo(Request $request): Response {
|
||||
|
||||
return $this->redirectToRoute("app_minio_image",["file"=>"logo/".$request->getSession()->get("logolight")]);
|
||||
public function logo(Request $request): Response
|
||||
{
|
||||
return $this->redirectToRoute('app_minio_image', ['file' => 'logo/'.$request->getSession()->get('logolight')]);
|
||||
}
|
||||
|
||||
public function image(Request $request): Response
|
||||
{
|
||||
$file=$request->query->get("file");
|
||||
switch($file) {
|
||||
case "avatar/admin.jpg":
|
||||
case "avatar/noavatar.png":
|
||||
case "avatar/system.jpg":
|
||||
case "header/header.jpg":
|
||||
case "logo/logo.png":
|
||||
$file = "medias/".$file;
|
||||
$file = $request->query->get('file');
|
||||
switch ($file) {
|
||||
case 'avatar/admin.jpg':
|
||||
case 'avatar/noavatar.png':
|
||||
case 'avatar/system.jpg':
|
||||
case 'header/header.jpg':
|
||||
case 'logo/logo.png':
|
||||
$file = 'medias/'.$file;
|
||||
$filePath = $file;
|
||||
$content = file_get_contents($file);
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
// C'est une url = on affiche l'url
|
||||
if(stripos($file,"http")===0) {
|
||||
if (0 === stripos($file, 'http')) {
|
||||
$filePath = $file;
|
||||
$content = file_get_contents($file);
|
||||
}
|
||||
@ -76,7 +76,7 @@ class MinioController extends AbstractController
|
||||
$filePath = $this->minio->download($file, $file, true);
|
||||
$content = file_get_contents($filePath);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
return new Response($content, 200, [
|
||||
@ -88,7 +88,7 @@ class MinioController extends AbstractController
|
||||
|
||||
public function document(Request $request)
|
||||
{
|
||||
$file=$request->query->get("file");
|
||||
$file = $request->query->get('file');
|
||||
$filePath = $this->minio->download($file, $file, true);
|
||||
$content = file_get_contents($filePath);
|
||||
|
||||
|
@ -1,127 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Entity\Niveau01 as Entity;
|
||||
use App\Form\Niveau01Type as Form;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class Niveau01Controller extends AbstractController
|
||||
{
|
||||
private $data="niveau01";
|
||||
private $entity="App\Entity\Niveau01";
|
||||
private $twig="Niveau01/";
|
||||
private $route="app_admin_niveau01";
|
||||
|
||||
private $data = 'niveau01';
|
||||
private $entity = "App\Entity\Niveau01";
|
||||
private $twig = 'Niveau01/';
|
||||
private $route = 'app_admin_niveau01';
|
||||
|
||||
public function list($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"access"=>$access,
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function tablelist(Request $request,ManagerRegistry $em): Response
|
||||
{
|
||||
$query=$request->query->all();
|
||||
$start=$query['start'];
|
||||
$length=$query['length'];
|
||||
$search=$query['search'];
|
||||
$draw= $query['draw'];
|
||||
$ordercolumn=$query['order'][0]['column'];
|
||||
$orderdir=$query['order'][0]['dir'];
|
||||
public function tablelist(Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$query = $request->query->all();
|
||||
$start = $query['start'];
|
||||
$length = $query['length'];
|
||||
$search = $query['search'];
|
||||
$draw = $query['draw'];
|
||||
$ordercolumn = $query['order'][0]['column'];
|
||||
$orderdir = $query['order'][0]['dir'];
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity,'entity')->getQuery()->getSingleScalarResult();
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if(!$search||$search["value"]=="")
|
||||
if (!$search || '' == $search['value']) {
|
||||
$totalf = $total;
|
||||
else {
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->where('entity.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('entity')->from($this->entity,'entity');
|
||||
if($search&&$search["value"]!="") {
|
||||
$qb ->andWhere('entity.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
$qb->select('entity')->from($this->entity, 'entity');
|
||||
if ($search && '' != $search['value']) {
|
||||
$qb->andWhere('entity.label LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
|
||||
if($ordercolumn) {
|
||||
switch($ordercolumn) {
|
||||
case 1 :
|
||||
$qb->orderBy('entity.label',$orderdir);
|
||||
break;
|
||||
if ($ordercolumn) {
|
||||
switch ($ordercolumn) {
|
||||
case 1:
|
||||
$qb->orderBy('entity.label', $orderdir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach($datas as $data) {
|
||||
foreach ($datas as $data) {
|
||||
// Action
|
||||
$action = "";
|
||||
$action.="<a href='".$this->generateUrl($this->route.'_update', array('id'=>$data->getId()))."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
$action = '';
|
||||
$action .= "<a href='".$this->generateUrl($this->route.'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
|
||||
$tmp=array();
|
||||
array_push($tmp,$action);
|
||||
array_push($tmp,$data->getLabel());
|
||||
$tmp = [];
|
||||
array_push($tmp, $action);
|
||||
array_push($tmp, $data->getLabel());
|
||||
|
||||
if($this->getParameter("appMasteridentity")=="LDAP"||$this->getParameter("appSynchro")=="LDAP2NINE") array_push($tmp,$data->getLdapfilter());
|
||||
if($this->getParameter("appMasteridentity")=="SSO") array_push($tmp,$data->getAttributes());
|
||||
if ('LDAP' == $this->getParameter('appMasteridentity') || 'LDAP2NINE' == $this->getParameter('appSynchro')) {
|
||||
array_push($tmp, $data->getLdapfilter());
|
||||
}
|
||||
if ('SSO' == $this->getParameter('appMasteridentity')) {
|
||||
array_push($tmp, $data->getAttributes());
|
||||
}
|
||||
|
||||
array_push($output["data"],$tmp);
|
||||
array_push($output['data'], $tmp);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function submit($access,Request $request,ManagerRegistry $em): Response
|
||||
public function submit($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data = new Entity();
|
||||
$data->setApikey(Uuid::uuid4());
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"submit",
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"appSynchro"=>$this->GetParameter("appSynchro"),
|
||||
"appNiveau01label"=>$this->GetParameter("appNiveau01label"),
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'submit',
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'appSynchro' => $this->GetParameter('appSynchro'),
|
||||
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->persist($data);
|
||||
$em->getManager()->flush();
|
||||
@ -129,73 +131,77 @@ class Niveau01Controller extends AbstractController
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"mode"=>"submit",
|
||||
"form"=>$form->createView(),
|
||||
$this->data=>$data,
|
||||
"access"=>$access,
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
$this->data => $data,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function update($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"update",
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"appSynchro"=>$this->GetParameter("appSynchro"),
|
||||
"appNiveau01label"=>$this->GetParameter("appNiveau01label"),
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'update',
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'appSynchro' => $this->GetParameter('appSynchro'),
|
||||
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
"access" => $access
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function delete($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Tentative de suppression
|
||||
try{
|
||||
try {
|
||||
$em->getManager()->remove($data);
|
||||
$em->getManager()->flush();
|
||||
} catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
|
||||
|
||||
return $this->redirectToRoute($this->route.'_update', ['id' => $id]);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add("error", $e->getMessage());
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
}
|
||||
|
||||
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,328 +1,337 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Entity\Niveau02 as Entity;
|
||||
use App\Form\Niveau02Type as Form;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class Niveau02Controller extends AbstractController
|
||||
{
|
||||
private $data="niveau02";
|
||||
private $entity="App\Entity\Niveau02";
|
||||
private $twig="Niveau02/";
|
||||
private $route="app_admin_niveau02";
|
||||
|
||||
private $data = 'niveau02';
|
||||
private $entity = "App\Entity\Niveau02";
|
||||
private $twig = 'Niveau02/';
|
||||
private $route = 'app_admin_niveau02';
|
||||
|
||||
public function list($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"access"=>$access,
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function tablelist($access,Request $request,ManagerRegistry $em): Response
|
||||
{
|
||||
$query=$request->query->all();
|
||||
$start=$query['start'];
|
||||
$length=$query['length'];
|
||||
$search=$query['search'];
|
||||
$draw= $query['draw'];
|
||||
$ordercolumn=$query['order'][0]['column'];
|
||||
$orderdir=$query['order'][0]['dir'];
|
||||
$total=null;
|
||||
$totalf=null;
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
switch($access) {
|
||||
case "admin":
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity,'entity')->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
public function tablelist($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$query = $request->query->all();
|
||||
$start = $query['start'];
|
||||
$length = $query['length'];
|
||||
$search = $query['search'];
|
||||
$draw = $query['draw'];
|
||||
$ordercolumn = $query['order'][0]['column'];
|
||||
$orderdir = $query['order'][0]['dir'];
|
||||
$total = null;
|
||||
$totalf = null;
|
||||
|
||||
case "modo":
|
||||
// Nombre total d'enregistrement
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
|
||||
case 'modo':
|
||||
$total = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from("App\Entity\UserModo",'usermodo')
|
||||
->where("usermodo.niveau01 = entity.niveau01")
|
||||
->andWhere("usermodo.user = :user")
|
||||
->setParameter("user", $this->getUser())
|
||||
->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
->from($this->entity, 'entity')
|
||||
->from("App\Entity\UserModo", 'usermodo')
|
||||
->where('usermodo.niveau01 = entity.niveau01')
|
||||
->andWhere('usermodo.user = :user')
|
||||
->setParameter('user', $this->getUser())
|
||||
->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if(!$search||$search["value"]=="")
|
||||
if (!$search || '' == $search['value']) {
|
||||
$totalf = $total;
|
||||
else {
|
||||
switch($access) {
|
||||
case "admin":
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from("App\Entity\Niveau01",'niveau01')
|
||||
->from($this->entity, 'entity')
|
||||
->from("App\Entity\Niveau01", 'niveau01')
|
||||
->where('entity.niveau01=niveau01.id')
|
||||
->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
break;
|
||||
break;
|
||||
|
||||
case "modo":
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
case 'modo':
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from("App\Entity\Niveau01",'niveau01')
|
||||
->from("App\Entity\UserModo",'usermodo')
|
||||
->from($this->entity, 'entity')
|
||||
->from("App\Entity\Niveau01", 'niveau01')
|
||||
->from("App\Entity\UserModo", 'usermodo')
|
||||
->where('entity.niveau01=niveau01.id')
|
||||
->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value')
|
||||
->andWhere("usermodo.niveau01 = entity.niveau01")
|
||||
->andWhere("usermodo.user = :user")
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter("user", $this->getUser())
|
||||
->andWhere('usermodo.niveau01 = entity.niveau01')
|
||||
->andWhere('usermodo.user = :user')
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->setParameter('user', $this->getUser())
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
switch($access) {
|
||||
case "admin":
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$qb->select('entity')
|
||||
->from($this->entity,'entity')
|
||||
->from("App:Niveau01",'niveau01')
|
||||
->from($this->entity, 'entity')
|
||||
->from('App:Niveau01', 'niveau01')
|
||||
->where('entity.niveau01=niveau01.id');
|
||||
break;
|
||||
break;
|
||||
|
||||
case "modo":
|
||||
case 'modo':
|
||||
$qb->select('entity')
|
||||
->from($this->entity,'entity')
|
||||
->from("App:Niveau01",'niveau01')
|
||||
->from("App\Entity\UserModo",'usermodo')
|
||||
->from($this->entity, 'entity')
|
||||
->from('App:Niveau01', 'niveau01')
|
||||
->from("App\Entity\UserModo", 'usermodo')
|
||||
->where('entity.niveau01=niveau01.id')
|
||||
->andWhere("usermodo.niveau01 = entity.niveau01")
|
||||
->andWhere("usermodo.user = :user")
|
||||
->setParameter("user", $this->getUser());
|
||||
break;
|
||||
->andWhere('usermodo.niveau01 = entity.niveau01')
|
||||
->andWhere('usermodo.user = :user')
|
||||
->setParameter('user', $this->getUser());
|
||||
break;
|
||||
}
|
||||
|
||||
if($search&&$search["value"]!="") {
|
||||
$qb ->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
if ($search && '' != $search['value']) {
|
||||
$qb->andwhere('entity.label LIKE :value OR niveau01.label LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
|
||||
if($ordercolumn) {
|
||||
switch($ordercolumn) {
|
||||
case 1 :
|
||||
$qb->orderBy('niveau01.label',$orderdir);
|
||||
break;
|
||||
if ($ordercolumn) {
|
||||
switch ($ordercolumn) {
|
||||
case 1:
|
||||
$qb->orderBy('niveau01.label', $orderdir);
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
$qb->orderBy('entity.label',$orderdir);
|
||||
break;
|
||||
case 2:
|
||||
$qb->orderBy('entity.label', $orderdir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach($datas as $data) {
|
||||
foreach ($datas as $data) {
|
||||
// Action
|
||||
$action = "";
|
||||
switch($access) {
|
||||
case "admin":
|
||||
$action.="<a href='".$this->generateUrl($this->route.'_update', array('id'=>$data->getId()))."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
case "modo":
|
||||
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_modo_",$this->route).'_update', array('id'=>$data->getId()))."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
$action = '';
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$action .= "<a href='".$this->generateUrl($this->route.'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
case 'modo':
|
||||
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_modo_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
}
|
||||
|
||||
$tmp=array();
|
||||
array_push($tmp,$action);
|
||||
array_push($tmp,$data->getNiveau01()->getLabel());
|
||||
array_push($tmp,$data->getLabel());
|
||||
$tmp = [];
|
||||
array_push($tmp, $action);
|
||||
array_push($tmp, $data->getNiveau01()->getLabel());
|
||||
array_push($tmp, $data->getLabel());
|
||||
|
||||
array_push($output["data"],$tmp);
|
||||
array_push($output['data'], $tmp);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
}
|
||||
|
||||
public function selectlist(Request $request,ManagerRegistry $em): Response
|
||||
public function selectlist(Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$output=array();
|
||||
$page_limit=$request->query->get('page_limit');
|
||||
$q=$request->query->get('q');
|
||||
$niveau01id=$request->get('niveau01');
|
||||
$output = [];
|
||||
$page_limit = $request->query->get('page_limit');
|
||||
$q = $request->query->get('q');
|
||||
$niveau01id = $request->get('niveau01');
|
||||
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('entity')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->where('entity.label LIKE :value')
|
||||
->andwhere('entity.niveau01=:niveau01')
|
||||
->setParameter("value", "%".$q."%")
|
||||
->setParameter("niveau01", $niveau01id)
|
||||
->setParameter('value', '%'.$q.'%')
|
||||
->setParameter('niveau01', $niveau01id)
|
||||
->orderBy('entity.label');
|
||||
|
||||
$datas=$qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
|
||||
foreach($datas as $data) {
|
||||
array_push($output,array("id"=>$data->getId(),"text"=>$data->getLabel()));
|
||||
|
||||
$datas = $qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
|
||||
foreach ($datas as $data) {
|
||||
array_push($output, ['id' => $data->getId(), 'text' => $data->getLabel()]);
|
||||
}
|
||||
|
||||
$ret_string["results"]=$output;
|
||||
$response = new Response(json_encode($ret_string));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
return $response;
|
||||
}
|
||||
$ret_string['results'] = $output;
|
||||
$response = new Response(json_encode($ret_string));
|
||||
$response->headers->set('Content-Type', 'application/json');
|
||||
|
||||
public function submit($access,Request $request,ManagerRegistry $em): Response
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function submit($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data = new Entity();
|
||||
$data->setApikey(Uuid::uuid4());
|
||||
|
||||
// Controler les permissions
|
||||
$this->cansubmit($access,$em);
|
||||
$this->cansubmit($access, $em);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"submit",
|
||||
"access"=>$access,
|
||||
"userid"=>$this->getUser()->getId(),
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"appNiveau01label"=>$this->GetParameter("appNiveau01label"),
|
||||
"appNiveau02label"=>$this->GetParameter("appNiveau02label"),
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'submit',
|
||||
'access' => $access,
|
||||
'userid' => $this->getUser()->getId(),
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
||||
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->persist($data);
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"mode"=>"submit",
|
||||
"access"=>$access,
|
||||
"form"=>$form->createView(),
|
||||
$this->data=>$data,
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'mode' => 'submit',
|
||||
'access' => $access,
|
||||
'form' => $form->createView(),
|
||||
$this->data => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function update($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->canupdate($access,$data,$em);
|
||||
$this->canupdate($access, $data, $em);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"update",
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"appNiveau01label"=>$this->GetParameter("appNiveau01label"),
|
||||
"appNiveau02label"=>$this->GetParameter("appNiveau02label"),
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'update',
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
||||
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'access' => $access,
|
||||
'form' => $form->createView()
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'access' => $access,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function delete($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->canupdate($access,$data,$em);
|
||||
$this->canupdate($access, $data, $em);
|
||||
|
||||
// Tentative de suppression
|
||||
try{
|
||||
try {
|
||||
$em->getManager()->remove($data);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add("error", $e->getMessage());
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route)."_update",["id"=>$id]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
|
||||
|
||||
private function cansubmit($access,$em) {
|
||||
switch($access) {
|
||||
case "admin" : return true; break;
|
||||
case "modo" : return true; break;
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
private function cansubmit($access, $em)
|
||||
{
|
||||
switch ($access) {
|
||||
case 'admin': return true;
|
||||
break;
|
||||
case 'modo': return true;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
private function canupdate($access, $entity, $em)
|
||||
{
|
||||
switch ($access) {
|
||||
case 'admin': return true;
|
||||
break;
|
||||
case 'modo':
|
||||
$usermodo = $em->getRepository("App\Entity\UserModo")->findOneBy(['user' => $this->getUser(), 'niveau01' => $entity->getNiveau01()]);
|
||||
if (!$usermodo) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
private function canupdate($access,$entity,$em) {
|
||||
switch($access) {
|
||||
case "admin" : return true; break;
|
||||
case "modo" :
|
||||
$usermodo=$em->getRepository("App\Entity\UserModo")->findOneBy(["user"=>$this->getUser(),"niveau01"=>$entity->getNiveau01()]);
|
||||
if(!$usermodo) throw $this->createAccessDeniedException('Permission denied');
|
||||
return true;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@ -9,24 +10,24 @@ use Symfony\Component\Mercure\Update;
|
||||
|
||||
class PublishController extends AbstractController
|
||||
{
|
||||
public function sample($id){
|
||||
return $this->render('Home/publishsample.html.twig',[
|
||||
'id'=>$id
|
||||
public function sample($id)
|
||||
{
|
||||
return $this->render('Home/publishsample.html.twig', [
|
||||
'id' => $id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function publish($channel, $id, Request $request, HubInterface $hub): Response
|
||||
{
|
||||
$ret=$request->get("msg");
|
||||
$ret["from"]=[];
|
||||
$ret["from"]["id"]=$this->getUser()->getId();
|
||||
$ret["from"]["username"]=$this->getUser()->getUsername();
|
||||
$ret["from"]["displayname"]=$this->getUser()->getDisplayname();
|
||||
$ret["from"]["avatar"]=$this->generateUrl('app_minio_image',["file"=>"avatar/".$this->getUser()->getAvatar()]);
|
||||
|
||||
$ret = $request->get('msg');
|
||||
$ret['from'] = [];
|
||||
$ret['from']['id'] = $this->getUser()->getId();
|
||||
$ret['from']['username'] = $this->getUser()->getUsername();
|
||||
$ret['from']['displayname'] = $this->getUser()->getDisplayname();
|
||||
$ret['from']['avatar'] = $this->generateUrl('app_minio_image', ['file' => 'avatar/'.$this->getUser()->getAvatar()]);
|
||||
|
||||
$update = new Update(
|
||||
$channel."-".$id,
|
||||
$channel.'-'.$id,
|
||||
json_encode(
|
||||
['ret' => $ret])
|
||||
);
|
||||
@ -35,4 +36,4 @@ class PublishController extends AbstractController
|
||||
|
||||
return new Response('published!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,224 +2,223 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use App\Service\MailService;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Registration;
|
||||
use App\Entity\User;
|
||||
use App\Form\RegistrationType as Form;
|
||||
use App\Form\ResetpwdType;
|
||||
use App\Service\MailService;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
class RegistrationController extends AbstractController
|
||||
{
|
||||
private $data="registration";
|
||||
private $entity="App\Entity\Registration";
|
||||
private $twig="Registration/";
|
||||
private $route="app_admin_registration";
|
||||
private $data = 'registration';
|
||||
private $entity = "App\Entity\Registration";
|
||||
private $twig = 'Registration/';
|
||||
private $route = 'app_admin_registration';
|
||||
|
||||
private $mail;
|
||||
public function __construct(MailService $mail) {
|
||||
|
||||
public function __construct(MailService $mail)
|
||||
{
|
||||
$this->mail = $mail;
|
||||
}
|
||||
|
||||
public function list($access)
|
||||
{
|
||||
$appmoderegistration = $this->getParameter('appModeregistration');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
if($appmoderegistration=="none"||$appMasteridentity!="SQL")
|
||||
$appmoderegistration = $this->getParameter('appModeregistration');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
if ('none' == $appmoderegistration || 'SQL' != $appMasteridentity) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'access' => $access,
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function tablelist($access, Request $request,ManagerRegistry $em): Response
|
||||
public function tablelist($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
|
||||
$query=$request->query->all();
|
||||
$start=$query['start'];
|
||||
$length=$query['length'];
|
||||
$search=$query['search'];
|
||||
$draw= $query['draw'];
|
||||
$ordercolumn=$query['order'][0]['column'];
|
||||
$orderdir=$query['order'][0]['dir'];
|
||||
$usermodo=null;
|
||||
|
||||
$query = $request->query->all();
|
||||
$start = $query['start'];
|
||||
$length = $query['length'];
|
||||
$search = $query['search'];
|
||||
$draw = $query['draw'];
|
||||
$ordercolumn = $query['order'][0]['column'];
|
||||
$orderdir = $query['order'][0]['dir'];
|
||||
$usermodo = null;
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
if($access=="admin")
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity,'entity')->getQuery()->getSingleScalarResult();
|
||||
else {
|
||||
$usermodo=$this->getUser();
|
||||
if ('admin' == $access) {
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
||||
} else {
|
||||
$usermodo = $this->getUser();
|
||||
$total = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from("App:UserModo",'usermodo')
|
||||
->where("usermodo.niveau01 = entity.niveau01")
|
||||
->andWhere("usermodo.user = :user")
|
||||
->setParameter("user", $usermodo)
|
||||
->getQuery()->getSingleScalarResult();
|
||||
->from($this->entity, 'entity')
|
||||
->from('App:UserModo', 'usermodo')
|
||||
->where('usermodo.niveau01 = entity.niveau01')
|
||||
->andWhere('usermodo.user = :user')
|
||||
->setParameter('user', $usermodo)
|
||||
->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if($search["value"]=="")
|
||||
if ('' == $search['value']) {
|
||||
$totalf = $total;
|
||||
else {
|
||||
if($access=="admin")
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
if ('admin' == $access) {
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->where('entity.username LIKE :value')
|
||||
->orWhere('entity.email LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
else
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from("App:UserModo",'usermodo')
|
||||
->from($this->entity, 'entity')
|
||||
->from('App:UserModo', 'usermodo')
|
||||
->where('entity.username LIKE :value OR entity.email LIKE :value')
|
||||
->andWhere("usermodo.niveau01 = entity.niveau01")
|
||||
->andWhere("usermodo.user = :user")
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter("user", $usermodo)
|
||||
->andWhere('usermodo.niveau01 = entity.niveau01')
|
||||
->andWhere('usermodo.user = :user')
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->setParameter('user', $usermodo)
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
if($this->isGranted('ROLE_ADMIN')) {
|
||||
$qb->select('entity')->from($this->entity,'entity')->from('App:Niveau01','niveau01');
|
||||
if ($this->isGranted('ROLE_ADMIN')) {
|
||||
$qb->select('entity')->from($this->entity, 'entity')->from('App:Niveau01', 'niveau01');
|
||||
$qb->where('entity.niveau01=niveau01.id');
|
||||
}
|
||||
else{
|
||||
$qb->select('entity')->from($this->entity,'entity')->from('App:Niveau01','niveau01')->from("App:UserModo",'usermodo');
|
||||
} else {
|
||||
$qb->select('entity')->from($this->entity, 'entity')->from('App:Niveau01', 'niveau01')->from('App:UserModo', 'usermodo');
|
||||
$qb->where('entity.niveau01=niveau01.id')
|
||||
->andWhere("usermodo.niveau01 = entity.niveau01")
|
||||
->andWhere("usermodo.user = :user")
|
||||
->setParameter("user", $usermodo);
|
||||
->andWhere('usermodo.niveau01 = entity.niveau01')
|
||||
->andWhere('usermodo.user = :user')
|
||||
->setParameter('user', $usermodo);
|
||||
}
|
||||
|
||||
|
||||
if($search["value"]!="") {
|
||||
$qb ->andWhere('entity.username LIKE :value OR entity.email LIKE :value OR niveau01.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
if ('' != $search['value']) {
|
||||
$qb->andWhere('entity.username LIKE :value OR entity.email LIKE :value OR niveau01.label LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
switch($ordercolumn) {
|
||||
case 1 :
|
||||
$qb->orderBy('entity.username',$orderdir);
|
||||
break;
|
||||
switch ($ordercolumn) {
|
||||
case 1:
|
||||
$qb->orderBy('entity.username', $orderdir);
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
$qb->orderBy('entity.email',$orderdir);
|
||||
break;
|
||||
case 2:
|
||||
$qb->orderBy('entity.email', $orderdir);
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
$qb->orderBy('entity.label',$orderdir);
|
||||
break;
|
||||
|
||||
case 4 :
|
||||
$qb->orderBy('entity.statut',$orderdir);
|
||||
break;
|
||||
case 3:
|
||||
$qb->orderBy('entity.label', $orderdir);
|
||||
break;
|
||||
|
||||
case 5 :
|
||||
$qb->orderBy('entity.keyexpire',$orderdir);
|
||||
break;
|
||||
case 4:
|
||||
$qb->orderBy('entity.statut', $orderdir);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$qb->orderBy('entity.keyexpire', $orderdir);
|
||||
break;
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach($datas as $data) {
|
||||
$action ="";
|
||||
foreach ($datas as $data) {
|
||||
$action = '';
|
||||
// Si inscription non périmée
|
||||
if($data->getStatut()<=2) {
|
||||
$action.="<a href='".$this->generateUrl('app_'.$access.'_registration_update', array('id'=>$data->getId()))."'><i class='fa fa-envelope fa-2x fa-fw'></i></a>";
|
||||
if ($data->getStatut() <= 2) {
|
||||
$action .= "<a href='".$this->generateUrl('app_'.$access.'_registration_update', ['id' => $data->getId()])."'><i class='fa fa-envelope fa-2x fa-fw'></i></a>";
|
||||
}
|
||||
|
||||
$statut="";
|
||||
switch($data->getStatut()) {
|
||||
case 1: $statut='En attente validation Administration'; break;
|
||||
case 2: $statut='En attente validation Utilisateur'; break;
|
||||
case 3: $statut='Inscription expirée'; break;
|
||||
$statut = '';
|
||||
switch ($data->getStatut()) {
|
||||
case 1: $statut = 'En attente validation Administration';
|
||||
break;
|
||||
case 2: $statut = 'En attente validation Utilisateur';
|
||||
break;
|
||||
case 3: $statut = 'Inscription expirée';
|
||||
break;
|
||||
}
|
||||
|
||||
array_push($output["data"],array(
|
||||
array_push($output['data'], [
|
||||
$action,
|
||||
$data->getUsername(),
|
||||
$data->getEmail(),
|
||||
$data->getNiveau01()->getLabel(),
|
||||
$statut,
|
||||
(is_null($data->getKeyexpire())?"":$data->getKeyexpire()->format('d/m/Y H:i:s'))
|
||||
));
|
||||
is_null($data->getKeyexpire()) ? '' : $data->getKeyexpire()->format('d/m/Y H:i:s'),
|
||||
]);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function submit(Request $request,ManagerRegistry $em): Response
|
||||
public function submit(Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$appmoderegistration = $this->getParameter('appModeregistration');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
$appmoderegistration = $this->getParameter('appModeregistration');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
|
||||
if($appmoderegistration=="none"||$appMasteridentity!="SQL")
|
||||
if ('none' == $appmoderegistration || 'SQL' != $appMasteridentity) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
$data = new Registration();
|
||||
$data->setIsvisible(true);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"submit",
|
||||
"access"=>"user",
|
||||
"userid"=>null,
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"appNiveau01label"=>$this->GetParameter("appNiveau01label"),
|
||||
"appNiveau02label"=>$this->GetParameter("appNiveau02label"),
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'submit',
|
||||
'access' => 'user',
|
||||
'userid' => null,
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
||||
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// si mode de registration BYUSER
|
||||
if($appmoderegistration=="BYUSER") {
|
||||
$idstatut=2;
|
||||
}
|
||||
else {
|
||||
if ('BYUSER' == $appmoderegistration) {
|
||||
$idstatut = 2;
|
||||
} else {
|
||||
// On recherche le domaine du mail dans la liste blanche
|
||||
$email=explode("@",$data->getEmail());
|
||||
$domaine=end($email);
|
||||
$whitelist = $em->getRepository("App\Entity\Whitelist")->findBy(["label"=>$domaine]);
|
||||
$idstatut=(!$whitelist?1:2);
|
||||
$email = explode('@', $data->getEmail());
|
||||
$domaine = end($email);
|
||||
$whitelist = $em->getRepository("App\Entity\Whitelist")->findBy(['label' => $domaine]);
|
||||
$idstatut = (!$whitelist ? 1 : 2);
|
||||
}
|
||||
$data->setStatut($idstatut);
|
||||
|
||||
// Sur erreur
|
||||
$this->getErrorForm(null,$form,$request,$data,"submit",$idstatut,$em);
|
||||
$this->getErrorForm(null, $form, $request, $data, 'submit', $idstatut, $em);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
@ -228,79 +227,78 @@ class RegistrationController extends AbstractController
|
||||
$appname = $request->getSession()->get('appname');
|
||||
$noreply = $this->getParameter('appMailnoreply');
|
||||
$appModeregistrationterme = $this->getParameter('appModeregistrationterme');
|
||||
|
||||
|
||||
// si non : validation par administrateur
|
||||
if($idstatut==1) {
|
||||
if (1 == $idstatut) {
|
||||
// Email à destination de l'inscript pour le prévenir qu'un administrateur doit valider
|
||||
$subject=$appname." : Inscription en cours de validation";
|
||||
$body="Votre inscription a bien été enregistrée.<br>Cependant, un administrateur doit encore valider votre inscription avant que celle-ci ne devienne effective.<br><br>Vous recevrez un mail quand votre inscription sera validée";
|
||||
$info=$body;
|
||||
$subject = $appname.' : Inscription en cours de validation';
|
||||
$body = 'Votre inscription a bien été enregistrée.<br>Cependant, un administrateur doit encore valider votre inscription avant que celle-ci ne devienne effective.<br><br>Vous recevrez un mail quand votre inscription sera validée';
|
||||
$info = $body;
|
||||
$to = $data->getEmail();
|
||||
$from = $noreply;
|
||||
$from = $noreply;
|
||||
$fromName = $appname;
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
|
||||
// Email à l'ensemble administrateurs pour les prévenir qu'il y a une personne à valider
|
||||
$url = $this->generateUrl('app_admin_registration', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$to=array();
|
||||
$from = $noreply;
|
||||
$fromName = $appname;
|
||||
$subject=$appname." : Inscription à valider";
|
||||
$motivation = "Login = ".$data->getUsername()."<br>";
|
||||
$motivation.= "Nom = ".$data->getLastname()."<br>";
|
||||
$motivation.= "Prénom = ".$data->getFirstname()."<br>";
|
||||
$motivation.= "Mail = ".$data->getEmail()."<br>";
|
||||
$motivation.= $this->getParameter("appNiveau01label")." = ".$data->getNiveau01()->getLabel();
|
||||
$motivation.= $data->getMotivation();
|
||||
$body="Un utilisateur dont le mail n’est pas en liste blanche souhaite s’inscrire à ".$appname.".\nMerci d’approuver son inscription pour finaliser celle-ci.<br><br>Veuillez vérifier cette inscription à cette adresse:<br><a href='$url'>$url</a><br><br>".$motivation;
|
||||
$emailadmins= $em ->getManager()->createQueryBuilder()
|
||||
$to = [];
|
||||
$from = $noreply;
|
||||
$fromName = $appname;
|
||||
$subject = $appname.' : Inscription à valider';
|
||||
$motivation = 'Login = '.$data->getUsername().'<br>';
|
||||
$motivation .= 'Nom = '.$data->getLastname().'<br>';
|
||||
$motivation .= 'Prénom = '.$data->getFirstname().'<br>';
|
||||
$motivation .= 'Mail = '.$data->getEmail().'<br>';
|
||||
$motivation .= $this->getParameter('appNiveau01label').' = '.$data->getNiveau01()->getLabel();
|
||||
$motivation .= $data->getMotivation();
|
||||
$body = 'Un utilisateur dont le mail n’est pas en liste blanche souhaite s’inscrire à '.$appname.".\nMerci d’approuver son inscription pour finaliser celle-ci.<br><br>Veuillez vérifier cette inscription à cette adresse:<br><a href='$url'>$url</a><br><br>".$motivation;
|
||||
$emailadmins = $em->getManager()->createQueryBuilder()
|
||||
->select('table.email')
|
||||
->from("App:User",'table')
|
||||
->from('App:User', 'table')
|
||||
->where('table.roles LIKE :value')
|
||||
->setParameter("value", "%ROLE_ADMIN%")
|
||||
->setParameter('value', '%ROLE_ADMIN%')
|
||||
->getQuery()
|
||||
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
|
||||
foreach($emailadmins as $emailadmin) {
|
||||
array_push($to,$emailadmin["email"]);
|
||||
foreach ($emailadmins as $emailadmin) {
|
||||
array_push($to, $emailadmin['email']);
|
||||
}
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
|
||||
// Email à l'ensemble des modérateurs du service pour les prévenir qu'il y a une personne à valider
|
||||
$niveau01id=$data->getNiveau01()->getId();
|
||||
$niveau01id = $data->getNiveau01()->getId();
|
||||
$url = $this->generateUrl('app_modo_registration', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$to=array();
|
||||
$from = $noreply;
|
||||
$fromName = $appname;
|
||||
$subject=$appname." : Inscription à valider";
|
||||
$motivation = "Login = ".$data->getUsername()."<br>";
|
||||
$motivation.= "Nom = ".$data->getLastname()."<br>";
|
||||
$motivation.= "Prénom = ".$data->getFirstname()."<br>";
|
||||
$motivation.= "Mail = ".$data->getEmail()."<br>";
|
||||
$motivation.= $this->getParameter("appNiveau01label")." = ".$data->getNiveau01()->getLabel();
|
||||
$motivation.= $data->getMotivation();
|
||||
$body="Un utilisateur dont le mail n’est pas en liste blanche souhaite s’inscrire à ".$appname.".\nMerci d’approuver son inscription pour finaliser celle-ci.<br><br>Veuillez vérifier cette inscription à cette adresse:<br><a href='$url'>$url</a><br><br>".$motivation;
|
||||
$emailmodos= $em ->getManager()->createQueryBuilder()
|
||||
$to = [];
|
||||
$from = $noreply;
|
||||
$fromName = $appname;
|
||||
$subject = $appname.' : Inscription à valider';
|
||||
$motivation = 'Login = '.$data->getUsername().'<br>';
|
||||
$motivation .= 'Nom = '.$data->getLastname().'<br>';
|
||||
$motivation .= 'Prénom = '.$data->getFirstname().'<br>';
|
||||
$motivation .= 'Mail = '.$data->getEmail().'<br>';
|
||||
$motivation .= $this->getParameter('appNiveau01label').' = '.$data->getNiveau01()->getLabel();
|
||||
$motivation .= $data->getMotivation();
|
||||
$body = 'Un utilisateur dont le mail n’est pas en liste blanche souhaite s’inscrire à '.$appname.".\nMerci d’approuver son inscription pour finaliser celle-ci.<br><br>Veuillez vérifier cette inscription à cette adresse:<br><a href='$url'>$url</a><br><br>".$motivation;
|
||||
$emailmodos = $em->getManager()->createQueryBuilder()
|
||||
->select('user.email')
|
||||
->from("App:UserModo",'usermodo')
|
||||
->from("App:User",'user')
|
||||
->where("usermodo.niveau01 = :niveau01id")
|
||||
->andWhere("user.id = usermodo.user")
|
||||
->from('App:UserModo', 'usermodo')
|
||||
->from('App:User', 'user')
|
||||
->where('usermodo.niveau01 = :niveau01id')
|
||||
->andWhere('user.id = usermodo.user')
|
||||
->andWhere('user.roles LIKE :value')
|
||||
->setParameter("niveau01id", $niveau01id)
|
||||
->setParameter("value", "%ROLE_MODO%")
|
||||
->setParameter('niveau01id', $niveau01id)
|
||||
->setParameter('value', '%ROLE_MODO%')
|
||||
->getQuery()
|
||||
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
|
||||
foreach($emailmodos as $emailmodo) {
|
||||
array_push($to,$emailmodo["email"]);
|
||||
foreach ($emailmodos as $emailmodo) {
|
||||
array_push($to, $emailmodo['email']);
|
||||
}
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
}
|
||||
|
||||
// si oui : Domaine de confiance : email de validation d'inscription directement à l'utilisateur
|
||||
else {
|
||||
// Génération de la date de fin de validité de la clé
|
||||
$keyexpire=new \DateTime();
|
||||
$keyexpire = new \DateTime();
|
||||
$keyexpire->add(new \DateInterval('PT'.$appModeregistrationterme.'H'));
|
||||
|
||||
// Enregistrement des valeurs
|
||||
@ -308,88 +306,89 @@ class RegistrationController extends AbstractController
|
||||
$data->setKeyexpire($keyexpire);
|
||||
|
||||
// Email à l'utilisateur
|
||||
$url = $this->generateUrl('app_registration_validation', array("key"=>$data->getKeyvalue()), UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$subject=$appname." : confirmation de validation";
|
||||
$body="<p>Merci de confirmer votre inscription en cliquant sur le lien suivant</p><p><a href='".$url."'>".$url."</a></p><br><p>Attention vous disposez d’un délai de 8 heures pour le faire. Passé ce délai, vous devrez vous réinscrire.</p>";
|
||||
$info="Vous allez recevoir un mail de confirmation pour finaliser votre inscription";
|
||||
$url = $this->generateUrl('app_registration_validation', ['key' => $data->getKeyvalue()], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$subject = $appname.' : confirmation de validation';
|
||||
$body = "<p>Merci de confirmer votre inscription en cliquant sur le lien suivant</p><p><a href='".$url."'>".$url.'</a></p><br><p>Attention vous disposez d’un délai de 8 heures pour le faire. Passé ce délai, vous devrez vous réinscrire.</p>';
|
||||
$info = 'Vous allez recevoir un mail de confirmation pour finaliser votre inscription';
|
||||
$to = $data->getEmail();
|
||||
$from = $noreply;
|
||||
$from = $noreply;
|
||||
$fromName = $appname;
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
}
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->persist($data);
|
||||
$em->getManager()->flush();
|
||||
|
||||
|
||||
// A voir retour sur un écran d'info indiquant si validation par admion ou s'il doit matter ses email
|
||||
$request->getSession()->set('registrationinfo', $info);
|
||||
$request->getSession()->set('registrationmode', "info");
|
||||
$request->getSession()->set('registrationmode', 'info');
|
||||
$request->getSession()->set('registrationredirectto', null);
|
||||
|
||||
return $this->redirectToRoute('app_registration_info');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1200,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView()
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1200,
|
||||
$this->data => $data,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function info(Request $request)
|
||||
{
|
||||
$info = $request->getSession()->get('registrationinfo');
|
||||
$mode = $request->getSession()->get('registrationmode');
|
||||
$redirectto = $request->getSession()->get('registrationredirectto');
|
||||
|
||||
|
||||
return $this->render($this->twig.'info.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxwidth' => true,
|
||||
'info' => $info,
|
||||
'mode' => $mode,
|
||||
'redirectto' => $redirectto,
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxwidth' => true,
|
||||
'info' => $info,
|
||||
'mode' => $mode,
|
||||
'redirectto' => $redirectto,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function update($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$appname = $request->getSession()->get('appname');
|
||||
$noreply = $this->getParameter('appMailnoreply');
|
||||
$appModeregistrationterme = $this->getParameter('appModeregistrationterme');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
|
||||
if($appModeregistrationterme=="none"||$appMasteridentity!="SQL")
|
||||
if ('none' == $appModeregistrationterme || 'SQL' != $appMasteridentity) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
|
||||
}
|
||||
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->canupdate($access,$data,$em);
|
||||
$this->canupdate($access, $data, $em);
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"update",
|
||||
"access"=>$access,
|
||||
"userid"=>$this->getUser()->getId(),
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"appNiveau01label"=>$this->GetParameter("appNiveau01label"),
|
||||
"appNiveau02label"=>$this->GetParameter("appNiveau02label"),
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'update',
|
||||
'access' => $access,
|
||||
'userid' => $this->getUser()->getId(),
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
||||
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('save')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
@ -398,19 +397,19 @@ class RegistrationController extends AbstractController
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
|
||||
$appname = $request->getSession()->get('appname');
|
||||
$noreply = $this->getParameter('appMailnoreply');
|
||||
$appModeregistrationterme = $this->getParameter('appModeregistrationterme');
|
||||
|
||||
|
||||
// Génération de la date de fin de validité de la clé
|
||||
$keyexpire=new \DateTime();
|
||||
$keyexpire = new \DateTime();
|
||||
$keyexpire->add(new \DateInterval('PT'.$appModeregistrationterme.'H'));
|
||||
|
||||
// Enregistrement des valeurs
|
||||
@ -421,11 +420,11 @@ class RegistrationController extends AbstractController
|
||||
$data->setStatut(2);
|
||||
|
||||
// Email à l'utilisateur
|
||||
$url = $this->generateUrl('app_registration_validation', array("key"=>$data->getKeyvalue()), UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$subject=$appname." : confirmation de validation";
|
||||
$body="<p>Merci de confirmer votre inscription en cliquant sur le lien suivant</p><p><a href='".$url."'>".$url."</a></p><br><p>Attention vous disposez d’un délai de 8 heures pour le faire. Passé ce délai, vous devrez vous réinscrire.</p>";
|
||||
$url = $this->generateUrl('app_registration_validation', ['key' => $data->getKeyvalue()], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$subject = $appname.' : confirmation de validation';
|
||||
$body = "<p>Merci de confirmer votre inscription en cliquant sur le lien suivant</p><p><a href='".$url."'>".$url.'</a></p><br><p>Attention vous disposez d’un délai de 8 heures pour le faire. Passé ce délai, vous devrez vous réinscrire.</p>';
|
||||
$to = $data->getEmail();
|
||||
$from = $noreply;
|
||||
$from = $noreply;
|
||||
$fromName = $appname;
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
|
||||
@ -433,60 +432,60 @@ class RegistrationController extends AbstractController
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'access' => $access,
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'access' => $access,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function validation($key,Request $request,ManagerRegistry $em)
|
||||
public function validation($key, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
$appmoderegistration = $this->getParameter('appModeregistration');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
$appmoderegistration = $this->getParameter('appModeregistration');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
|
||||
if($appmoderegistration=="none"||$appMasteridentity!="SQL")
|
||||
if ('none' == $appmoderegistration || 'SQL' != $appMasteridentity) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
$now=new \DateTime();
|
||||
|
||||
$data = $em ->getManager()->createQueryBuilder()
|
||||
$now = new \DateTime();
|
||||
|
||||
$data = $em->getManager()->createQueryBuilder()
|
||||
->select('entity')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->where('entity.keyvalue= :key')
|
||||
->andWhere('entity.keyexpire >= :date')
|
||||
->setParameter("key", $key)
|
||||
->setParameter("date", $now)
|
||||
->setParameter('key', $key)
|
||||
->setParameter('date', $now)
|
||||
->getQuery()
|
||||
->getSingleResult();
|
||||
|
||||
if(!$data) {
|
||||
$info="Clé de validation invalide";
|
||||
$mode="danger";
|
||||
if (!$data) {
|
||||
$info = 'Clé de validation invalide';
|
||||
$mode = 'danger';
|
||||
|
||||
$request->getSession()->set('registrationinfo', $info);
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
$request->getSession()->set('registrationredirectto', null);
|
||||
}
|
||||
else {
|
||||
$url=$this->generateUrl('app_login');
|
||||
$info="<p>Votre compte est à présent activé</p><p>Vous allez être redirigé vers la mire de connexion</p><p><a href='".$url."'>Connexion</a>";
|
||||
$mode="success";
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
$request->getSession()->set('registrationredirectto', null);
|
||||
} else {
|
||||
$url = $this->generateUrl('app_login');
|
||||
$info = "<p>Votre compte est à présent activé</p><p>Vous allez être redirigé vers la mire de connexion</p><p><a href='".$url."'>Connexion</a>";
|
||||
$mode = 'success';
|
||||
|
||||
$request->getSession()->set('registrationinfo', $info);
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
|
||||
// Initialisation de l'enregistrement
|
||||
$user = new User();
|
||||
$user->setAvatar("noavatar.png");
|
||||
$user->setAvatar('noavatar.png');
|
||||
$user->setUsername($data->getUsername());
|
||||
$user->setEmail($data->getEmail());
|
||||
$user->setLastname($data->getLastname());
|
||||
@ -505,7 +504,7 @@ class RegistrationController extends AbstractController
|
||||
$user->setPostaladress($data->getPostaladress());
|
||||
$user->setJob($data->getJob());
|
||||
$user->setPosition($data->getPosition());
|
||||
$user->setRoles(["ROLE_USER"]);
|
||||
$user->setRoles(['ROLE_USER']);
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->persist($user);
|
||||
@ -515,77 +514,79 @@ class RegistrationController extends AbstractController
|
||||
$em->getManager()->remove($data);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
|
||||
|
||||
return $this->redirectToRoute('app_registration_info');
|
||||
}
|
||||
|
||||
|
||||
public function delete($id,$access,Request $request,ManagerRegistry $em)
|
||||
public function delete($id, $access, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->candelete($access,$data,$em);
|
||||
|
||||
$this->candelete($access, $data, $em);
|
||||
|
||||
// Tentative de suppression
|
||||
try{
|
||||
try {
|
||||
$em->getManager()->remove($data);
|
||||
$em->getManager()->flush();
|
||||
} catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
|
||||
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add("error", $e->getMessage());
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route)."_update",["id"=>$id]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
public function resetpwd01(Request $request,ManagerRegistry $em)
|
||||
public function resetpwd01(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
$appmoderegistration = $this->getParameter('appModeregistration');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
if($appMasteridentity!="SQL")
|
||||
$appmoderegistration = $this->getParameter('appModeregistration');
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
if ('SQL' != $appMasteridentity) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(ResetpwdType::class,null,array("mode"=>"resetpwd01"));
|
||||
$form = $this->createForm(ResetpwdType::class, null, ['mode' => 'resetpwd01']);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
$data = $form->getData();
|
||||
|
||||
if ($form->get('submit')->isClicked()) {
|
||||
$user=$em->getRepository("App\Entity\User")->findOneby(["email"=>$data->getEmail()]);
|
||||
$user = $em->getRepository("App\Entity\User")->findOneby(['email' => $data->getEmail()]);
|
||||
|
||||
// On s'assure que le mail existe dans la base des utilisateurs
|
||||
if(!$user) {
|
||||
$request->getSession()->getFlashBag()->add("error", 'Mail inconnu');
|
||||
if (!$user) {
|
||||
$request->getSession()->getFlashBag()->add('error', 'Mail inconnu');
|
||||
|
||||
// Affichage du formulaire
|
||||
dump("here");
|
||||
dump('here');
|
||||
|
||||
return $this->render($this->twig.'resetpwd01.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1200,
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1200,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked()) {
|
||||
$user=$em->getRepository("App\Entity\User")->findOneby(["email"=>$data->getEmail()]);
|
||||
$user = $em->getRepository("App\Entity\User")->findOneby(['email' => $data->getEmail()]);
|
||||
|
||||
$appname = $request->getSession()->get('appname');
|
||||
$noreply = $this->getParameter('appMailnoreply');
|
||||
$appModeregistrationterme = $this->getParameter('appModeregistrationterme');
|
||||
|
||||
// Génération de la date de fin de validité de la clé
|
||||
$keyexpire=new \DateTime();
|
||||
$keyexpire = new \DateTime();
|
||||
$keyexpire->add(new \DateInterval('PT'.$appModeregistrationterme.'H'));
|
||||
|
||||
// Enregistrement des valeurs
|
||||
@ -596,67 +597,68 @@ class RegistrationController extends AbstractController
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Email au user
|
||||
$url = $this->generateUrl('app_resetpwd02', array("key"=>$user->getKeyvalue()), UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$subject=$appname." : réinitialisation mot de passe";
|
||||
$body="<p>Merci de réinitialiser votre mot de passe en cliquant sur le lien suivant</p><p><a href='".$url."'>".$url."</a></p><br><p>Attention vous disposez d’un délai de ".$appModeregistrationterme." heures pour le faire.</p><p>Vous pourrez par la suite vous connecter avec votre login : ".$user->getUsername()."</p>";
|
||||
$url = $this->generateUrl('app_resetpwd02', ['key' => $user->getKeyvalue()], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$subject = $appname.' : réinitialisation mot de passe';
|
||||
$body = "<p>Merci de réinitialiser votre mot de passe en cliquant sur le lien suivant</p><p><a href='".$url."'>".$url.'</a></p><br><p>Attention vous disposez d’un délai de '.$appModeregistrationterme.' heures pour le faire.</p><p>Vous pourrez par la suite vous connecter avec votre login : '.$user->getUsername().'</p>';
|
||||
$to = $user->getEmail();
|
||||
$from = $noreply;
|
||||
$from = $noreply;
|
||||
$fromName = $appname;
|
||||
$this->mail->sendEmail($subject, $body, $to, $from, $fromName);
|
||||
|
||||
|
||||
// Info
|
||||
$info="Vous allez recevoir un mail avec lien qui vous permettra de réinitialiser votre mot de passe";
|
||||
$mode="info";
|
||||
$info = 'Vous allez recevoir un mail avec lien qui vous permettra de réinitialiser votre mot de passe';
|
||||
$mode = 'info';
|
||||
$request->getSession()->set('registrationinfo', $info);
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
$request->getSession()->set('registrationredirectto', null);
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
$request->getSession()->set('registrationredirectto', null);
|
||||
|
||||
return $this->redirectToRoute('app_registration_info');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'resetpwd01.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1200,
|
||||
'form' => $form->createView()
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1200,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function resetpwd02($key,Request $request,ManagerRegistry $em)
|
||||
public function resetpwd02($key, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
if($appMasteridentity!="SQL")
|
||||
if ('SQL' != $appMasteridentity) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
|
||||
$now=new \DateTime();
|
||||
|
||||
$user = $em ->getManager()->createQueryBuilder()
|
||||
}
|
||||
|
||||
$now = new \DateTime();
|
||||
|
||||
$user = $em->getManager()->createQueryBuilder()
|
||||
->select('table')
|
||||
->from("App:User",'table')
|
||||
->from('App:User', 'table')
|
||||
->where('table.keyvalue= :key')
|
||||
->andWhere('table.keyexpire >= :date')
|
||||
->setParameter("key", $key)
|
||||
->setParameter("date", $now)
|
||||
->setParameter('key', $key)
|
||||
->setParameter('date', $now)
|
||||
->getQuery()
|
||||
->getSingleResult();
|
||||
|
||||
if(!$user) {
|
||||
$info="Clé de validation invalide";
|
||||
$mode="danger";
|
||||
if (!$user) {
|
||||
$info = 'Clé de validation invalide';
|
||||
$mode = 'danger';
|
||||
$request->getSession()->set('registrationinfo', $info);
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
$request->getSession()->set('registrationredirectto', null);
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
$request->getSession()->set('registrationredirectto', null);
|
||||
|
||||
return $this->redirectToRoute('app_registration_info');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(ResetpwdType::class,$user,array("mode"=>"resetpwd02"));
|
||||
$form = $this->createForm(ResetpwdType::class, $user, ['mode' => 'resetpwd02']);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$user->setKeyvalue(null);
|
||||
@ -664,74 +666,85 @@ class RegistrationController extends AbstractController
|
||||
$user->setPassword($data->getPassword());
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->flush();
|
||||
$em->getManager()->flush();
|
||||
|
||||
$url=$this->generateUrl('app_login');
|
||||
$info="<p>Nouveau mot de passe prise en compte</p><p>Vous allez être redirigé vers la mire de connexion</p><p><a href='".$url."'>Connexion</a>";
|
||||
$mode="success";
|
||||
$url = $this->generateUrl('app_login');
|
||||
$info = "<p>Nouveau mot de passe prise en compte</p><p>Vous allez être redirigé vers la mire de connexion</p><p><a href='".$url."'>Connexion</a>";
|
||||
$mode = 'success';
|
||||
$request->getSession()->set('registrationinfo', $info);
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
$request->getSession()->set('registrationredirectto', null);
|
||||
$request->getSession()->set('registrationmode', $mode);
|
||||
$request->getSession()->set('registrationredirectto', null);
|
||||
|
||||
return $this->redirectToRoute('app_registration_info');
|
||||
}
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'resetpwd02.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1200,
|
||||
'form' => $form->createView()
|
||||
]);
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'maxsize' => 1200,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function canupdate($access,$entity,$em) {
|
||||
switch($access) {
|
||||
case "admin" : return true; break;
|
||||
case "modo" :
|
||||
$usermodo=$em->getRepository("App\Entity\UserModo")->findOneBy(["user"=>$this->getUser(),"niveau01"=>$entity->getNiveau01()]);
|
||||
if(!$usermodo) throw $this->createAccessDeniedException('Permission denied');
|
||||
private function canupdate($access, $entity, $em)
|
||||
{
|
||||
switch ($access) {
|
||||
case 'admin': return true;
|
||||
break;
|
||||
case 'modo':
|
||||
$usermodo = $em->getRepository("App\Entity\UserModo")->findOneBy(['user' => $this->getUser(), 'niveau01' => $entity->getNiveau01()]);
|
||||
if (!$usermodo) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
}
|
||||
|
||||
private function candelete($access, $entity, $em)
|
||||
{
|
||||
switch ($access) {
|
||||
case 'admin': return true;
|
||||
break;
|
||||
case 'modo':
|
||||
$usermodo = $em->getRepository("App\Entity\UserModo")->findOneBy(['user' => $this->getUser(), 'niveau01' => $entity->getNiveau01()]);
|
||||
if (!$usermodo) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
private function candelete($access,$entity,$em) {
|
||||
switch($access) {
|
||||
case "admin" : return true; break;
|
||||
case "modo" :
|
||||
$usermodo=$em->getRepository("App\Entity\UserModo")->findOneBy(["user"=>$this->getUser(),"niveau01"=>$entity->getNiveau01()]);
|
||||
if(!$usermodo) throw $this->createAccessDeniedException('Permission denied');
|
||||
return true;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
}
|
||||
|
||||
protected function getErrorForm($id,$form,$request,$data,$mode,$idstatut,$em) {
|
||||
if ($form->get('submit')->isClicked() && $mode=="submit") {
|
||||
protected function getErrorForm($id, $form, $request, $data, $mode, $idstatut, $em)
|
||||
{
|
||||
if ($form->get('submit')->isClicked() && 'submit' == $mode) {
|
||||
// Si validation par administrateur demander une motivation
|
||||
$appmoderegistration = $this->getParameter('appModeregistration');
|
||||
if(is_null($data->getMotivation())&&$appmoderegistration=="BYADMIN") {
|
||||
if (is_null($data->getMotivation()) && 'BYADMIN' == $appmoderegistration) {
|
||||
// On recherche le domaine du mail dans la liste blanche
|
||||
$email=explode("@",$data->getEmail());
|
||||
$domaine=end($email);
|
||||
$whitelist = $em->getManager()->getRepository("App\Entity\Whitelist")->findBy(["label"=>$domaine]);
|
||||
if(!$whitelist)
|
||||
$form->addError(new FormError("Attention, le suffixe de votre adresse mail n’est pas dans la liste des administrations autorisées, merci de bien vouloir privilégier votre adresse professionnelle si vous en avez une.<br>Si ce n’est pas le cas, il faut que vous renseigniez la case motivation de votre demande"));
|
||||
$email = explode('@', $data->getEmail());
|
||||
$domaine = end($email);
|
||||
$whitelist = $em->getManager()->getRepository("App\Entity\Whitelist")->findBy(['label' => $domaine]);
|
||||
if (!$whitelist) {
|
||||
$form->addError(new FormError('Attention, le suffixe de votre adresse mail n’est pas dans la liste des administrations autorisées, merci de bien vouloir privilégier votre adresse professionnelle si vous en avez une.<br>Si ce n’est pas le cas, il faut que vous renseigniez la case motivation de votre demande'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->get('submit')->isClicked() && !$form->isValid()) {
|
||||
$errors = $form->getErrors();
|
||||
foreach( $errors as $error ) {
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
$request->getSession()->getFlashBag()->add("error", $error->getMessage());
|
||||
foreach ($errors as $error) {
|
||||
$request->getSession()->getFlashBag()->add('error', $error->getMessage());
|
||||
$request->getSession()->getFlashBag()->add('error', $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,22 +2,21 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use FOS\RestBundle\Controller\AbstractFOSRestController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use FOS\RestBundle\Controller\Annotations as FOSRest;
|
||||
use OpenApi\Annotations as OA;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class RestController extends AbstractFOSRestController
|
||||
{
|
||||
private $output=[];
|
||||
private $output = [];
|
||||
private $cpt;
|
||||
|
||||
/**
|
||||
* getAllUsers
|
||||
* getAllUsers.
|
||||
*
|
||||
*
|
||||
* @FOSRest\Get("/rest/getAllUsers")
|
||||
* @FOSRest\Get("/rest/getAllUsers")
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="get all users"
|
||||
@ -31,35 +30,33 @@ class RestController extends AbstractFOSRestController
|
||||
* @OA\Schema(type="string")
|
||||
* )
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function getAllUsers(Request $request,ManagerRegistry $em) {
|
||||
public function getAllUsers(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
// Récupération des parametres
|
||||
if(!$this->iskey($request->headers->get("key"))) {
|
||||
$view = $this->view("API Key inconnue", 403);
|
||||
return $this->handleView($view);
|
||||
if (!$this->iskey($request->headers->get('key'))) {
|
||||
$view = $this->view('API Key inconnue', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$users=$em->getRepository("App\Entity\User")->findAll();
|
||||
foreach($users as $user) {
|
||||
array_push($output,$this->userFormat($user));
|
||||
$users = $em->getRepository("App\Entity\User")->findAll();
|
||||
foreach ($users as $user) {
|
||||
array_push($output, $this->userFormat($user));
|
||||
}
|
||||
|
||||
$view = $this->view($output, 200);
|
||||
return $this->handleView($view);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getOneUser
|
||||
* getOneUser.
|
||||
*
|
||||
*
|
||||
* @FOSRest\Get("/rest/getOneUser")
|
||||
* @FOSRest\Get("/rest/getOneUser")
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="get one user by login"
|
||||
@ -80,36 +77,36 @@ class RestController extends AbstractFOSRestController
|
||||
* @OA\Schema(type="string")
|
||||
* )
|
||||
*/
|
||||
|
||||
|
||||
public function getOneUser(Request $request,ManagerRegistry $em) {
|
||||
public function getOneUser(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
// Récupération des parametres
|
||||
if(!$this->iskey($request->headers->get("key"))) {
|
||||
$view = $this->view("API Key inconnue", 403);
|
||||
return $this->handleView($view);
|
||||
if (!$this->iskey($request->headers->get('key'))) {
|
||||
$view = $this->view('API Key inconnue', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$user=$em->getRepository("App\Entity\User")->findOneBy(["username"=>$request->headers->get("login")]);
|
||||
if(!$user) {
|
||||
$view = $this->view("Utilisateur inconnue", 403);
|
||||
return $this->handleView($view);
|
||||
$user = $em->getRepository("App\Entity\User")->findOneBy(['username' => $request->headers->get('login')]);
|
||||
if (!$user) {
|
||||
$view = $this->view('Utilisateur inconnue', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output=$this->userFormat($user);
|
||||
$output = $this->userFormat($user);
|
||||
$view = $this->view($output, 200);
|
||||
return $this->handleView($view);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getAllNiveau01s
|
||||
* getAllNiveau01s.
|
||||
*
|
||||
*
|
||||
* @FOSRest\Get("/rest/getAllNiveau01s")
|
||||
* @FOSRest\Get("/rest/getAllNiveau01s")
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="get all niveau01"
|
||||
@ -123,34 +120,33 @@ class RestController extends AbstractFOSRestController
|
||||
* @OA\Schema(type="string")
|
||||
* )
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function getAllNiveau01s(Request $request,ManagerRegistry $em) {
|
||||
public function getAllNiveau01s(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
// Récupération des parametres
|
||||
if(!$this->iskey($request->headers->get("key"))) {
|
||||
$view = $this->view("API Key inconnue", 403);
|
||||
return $this->handleView($view);
|
||||
if (!$this->iskey($request->headers->get('key'))) {
|
||||
$view = $this->view('API Key inconnue', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$niveau01s=$em->getRepository("App\Entity\Niveau01")->findAll();
|
||||
foreach($niveau01s as $niveau01) {
|
||||
array_push($output,$this->niveau01Format($niveau01,true));
|
||||
$niveau01s = $em->getRepository("App\Entity\Niveau01")->findAll();
|
||||
foreach ($niveau01s as $niveau01) {
|
||||
array_push($output, $this->niveau01Format($niveau01, true));
|
||||
}
|
||||
|
||||
$view = $this->view($output, 200);
|
||||
return $this->handleView($view);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* getOneNiveau01
|
||||
* getOneNiveau01.
|
||||
*
|
||||
*
|
||||
* @FOSRest\Get("/rest/getOneNiveau01")
|
||||
* @FOSRest\Get("/rest/getOneNiveau01")
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="get one niveau01 by label"
|
||||
@ -171,36 +167,36 @@ class RestController extends AbstractFOSRestController
|
||||
* @OA\Schema(type="string")
|
||||
* )
|
||||
*/
|
||||
|
||||
|
||||
public function getOneNiveau01(Request $request,ManagerRegistry $em) {
|
||||
public function getOneNiveau01(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
// Récupération des parametres
|
||||
if(!$this->iskey($request->headers->get("key"))) {
|
||||
$view = $this->view("API Key inconnue", 403);
|
||||
return $this->handleView($view);
|
||||
if (!$this->iskey($request->headers->get('key'))) {
|
||||
$view = $this->view('API Key inconnue', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$niveau01=$em->getRepository("App\Entity\Niveau01")->findOneBy(["label"=>$request->headers->get("label")]);
|
||||
if(!$niveau01) {
|
||||
$view = $this->view("Niveau01 inconnu", 403);
|
||||
return $this->handleView($view);
|
||||
$niveau01 = $em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $request->headers->get('label')]);
|
||||
if (!$niveau01) {
|
||||
$view = $this->view('Niveau01 inconnu', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output=$this->niveau01Format($niveau01,true);
|
||||
$output = $this->niveau01Format($niveau01, true);
|
||||
$view = $this->view($output, 200);
|
||||
return $this->handleView($view);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getAllNiveau02s
|
||||
* getAllNiveau02s.
|
||||
*
|
||||
*
|
||||
* @FOSRest\Get("/rest/getAllNiveau02s")
|
||||
* @FOSRest\Get("/rest/getAllNiveau02s")
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="get all niveau02"
|
||||
@ -214,34 +210,33 @@ class RestController extends AbstractFOSRestController
|
||||
* @OA\Schema(type="string")
|
||||
* )
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function getAllNiveau02s(Request $request,ManagerRegistry $em) {
|
||||
public function getAllNiveau02s(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
// Récupération des parametres
|
||||
if(!$this->iskey($request->headers->get("key"))) {
|
||||
$view = $this->view("API Key inconnue", 403);
|
||||
return $this->handleView($view);
|
||||
if (!$this->iskey($request->headers->get('key'))) {
|
||||
$view = $this->view('API Key inconnue', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$niveau02s=$em->getRepository("App\Entity\Niveau02")->findAll();
|
||||
foreach($niveau02s as $niveau02) {
|
||||
array_push($output,$this->niveau02Format($niveau02,true));
|
||||
$niveau02s = $em->getRepository("App\Entity\Niveau02")->findAll();
|
||||
foreach ($niveau02s as $niveau02) {
|
||||
array_push($output, $this->niveau02Format($niveau02, true));
|
||||
}
|
||||
|
||||
$view = $this->view($output, 200);
|
||||
return $this->handleView($view);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* getOneNiveau02
|
||||
* getOneNiveau02.
|
||||
*
|
||||
*
|
||||
* @FOSRest\Get("/rest/getOneNiveau02")
|
||||
* @FOSRest\Get("/rest/getOneNiveau02")
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="get one niveau02 by label"
|
||||
@ -262,36 +257,36 @@ class RestController extends AbstractFOSRestController
|
||||
* @OA\Schema(type="string")
|
||||
* )
|
||||
*/
|
||||
|
||||
|
||||
public function getOneNiveau02(Request $request,ManagerRegistry $em) {
|
||||
public function getOneNiveau02(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
// Récupération des parametres
|
||||
if(!$this->iskey($request->headers->get("key"))) {
|
||||
$view = $this->view("API Key inconnue", 403);
|
||||
return $this->handleView($view);
|
||||
if (!$this->iskey($request->headers->get('key'))) {
|
||||
$view = $this->view('API Key inconnue', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$niveau02=$em->getRepository("App\Entity\Niveau02")->findOneBy(["label"=>$request->headers->get("label")]);
|
||||
if(!$niveau02) {
|
||||
$view = $this->view("Niveau02 inconnu", 403);
|
||||
return $this->handleView($view);
|
||||
$niveau02 = $em->getRepository("App\Entity\Niveau02")->findOneBy(['label' => $request->headers->get('label')]);
|
||||
if (!$niveau02) {
|
||||
$view = $this->view('Niveau02 inconnu', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output=$this->niveau02Format($niveau02,true);
|
||||
$output = $this->niveau02Format($niveau02, true);
|
||||
$view = $this->view($output, 200);
|
||||
return $this->handleView($view);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getAllGroups
|
||||
* getAllGroups.
|
||||
*
|
||||
*
|
||||
* @FOSRest\Get("/rest/getAllGroups")
|
||||
* @FOSRest\Get("/rest/getAllGroups")
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="get all group"
|
||||
@ -305,35 +300,36 @@ class RestController extends AbstractFOSRestController
|
||||
* @OA\Schema(type="string")
|
||||
* )
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function getAllGroups(Request $request,ManagerRegistry $em) {
|
||||
public function getAllGroups(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
// Récupération des parametres
|
||||
if(!$this->iskey($request->headers->get("key"))) {
|
||||
$view = $this->view("API Key inconnue", 403);
|
||||
return $this->handleView($view);
|
||||
if (!$this->iskey($request->headers->get('key'))) {
|
||||
$view = $this->view('API Key inconnue', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$groups=$em->getRepository("App\Entity\Group")->findAll();
|
||||
foreach($groups as $group) {
|
||||
if($group->getId()<0) continue;
|
||||
array_push($output,$this->groupFormat($group,true));
|
||||
$groups = $em->getRepository("App\Entity\Group")->findAll();
|
||||
foreach ($groups as $group) {
|
||||
if ($group->getId() < 0) {
|
||||
continue;
|
||||
}
|
||||
array_push($output, $this->groupFormat($group, true));
|
||||
}
|
||||
|
||||
$view = $this->view($output, 200);
|
||||
return $this->handleView($view);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* getOneGroup
|
||||
* getOneGroup.
|
||||
*
|
||||
*
|
||||
* @FOSRest\Get("/rest/getOneGroup")
|
||||
* @FOSRest\Get("/rest/getOneGroup")
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="get one group by label"
|
||||
@ -354,114 +350,131 @@ class RestController extends AbstractFOSRestController
|
||||
* @OA\Schema(type="string")
|
||||
* )
|
||||
*/
|
||||
|
||||
|
||||
public function getOneGroup(Request $request,ManagerRegistry $em) {
|
||||
public function getOneGroup(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
// Récupération des parametres
|
||||
if(!$this->iskey($request->headers->get("key"))) {
|
||||
$view = $this->view("API Key inconnue", 403);
|
||||
return $this->handleView($view);
|
||||
if (!$this->iskey($request->headers->get('key'))) {
|
||||
$view = $this->view('API Key inconnue', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$group=$em->getRepository("App\Entity\Group")->findOneBy(["label"=>$request->headers->get("label")]);
|
||||
if(!$group) {
|
||||
$view = $this->view("Group inconnu", 403);
|
||||
return $this->handleView($view);
|
||||
$group = $em->getRepository("App\Entity\Group")->findOneBy(['label' => $request->headers->get('label')]);
|
||||
if (!$group) {
|
||||
$view = $this->view('Group inconnu', 403);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
$output=$this->groupFormat($group,true);
|
||||
$output = $this->groupFormat($group, true);
|
||||
$view = $this->view($output, 200);
|
||||
return $this->handleView($view);
|
||||
|
||||
return $this->handleView($view);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private function iskey($key) {
|
||||
return ($key==$this->getParameter("appSecret"));
|
||||
private function iskey($key)
|
||||
{
|
||||
return $key == $this->getParameter('appSecret');
|
||||
}
|
||||
|
||||
private function userFormat($user) {
|
||||
$output=[];
|
||||
private function userFormat($user)
|
||||
{
|
||||
$output = [];
|
||||
|
||||
$output["userid"]=$user->getId();
|
||||
$output["userlogin"]=$user->getUsername();
|
||||
$output["userlastname"]=$user->getLastname();
|
||||
$output["userfirstname"]=$user->getFirstname();
|
||||
$output["useremail"]=$user->getEmail();
|
||||
$output["userjob"]=$user->getJob();
|
||||
$output["userposition"]=$user->getPosition();
|
||||
$output["userpostaladress"]=$user->getPostaladress();
|
||||
$output["usertelephonenumber"]=$user->getTelephonenumber();
|
||||
$output["useravatar"]="https://".str_replace("//","/",$this->getParameter("appWeburl").$this->getParameter("appAlias").$this->generateUrl('app_minio_image',["file"=>"avatar/".$user->getAvatar()],true));
|
||||
$output["userniveau01"]=$this->niveau01Format($user->getNiveau01());
|
||||
$output["userniveau02"]=$this->niveau02Format($user->getNiveau02());
|
||||
$output["usergroups"]=[];
|
||||
foreach($user->getGroups() as $usergroup) {
|
||||
$groupFormat=$this->groupFormat($usergroup->getGroup());
|
||||
if($groupFormat) array_push($output["usergroups"],$groupFormat);
|
||||
}
|
||||
if(empty($output["usergroups"])) $output["usergroups"]=null;
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function niveau01Format($niveau01,$withmembers=false){
|
||||
if(!$niveau01) return null;
|
||||
$output=[];
|
||||
$output["niveau01id"]=$niveau01->getId();
|
||||
$output["niveau01label"]=$niveau01->getLabel();
|
||||
|
||||
if($withmembers) {
|
||||
$output["niveau01users"]=[];
|
||||
foreach($niveau01->getUsers() as $user) {
|
||||
array_push($output["niveau01users"],["userid"=>$user->getId(),"userlogin"=>$user->getUsername()]);
|
||||
$output['userid'] = $user->getId();
|
||||
$output['userlogin'] = $user->getUsername();
|
||||
$output['userlastname'] = $user->getLastname();
|
||||
$output['userfirstname'] = $user->getFirstname();
|
||||
$output['useremail'] = $user->getEmail();
|
||||
$output['userjob'] = $user->getJob();
|
||||
$output['userposition'] = $user->getPosition();
|
||||
$output['userpostaladress'] = $user->getPostaladress();
|
||||
$output['usertelephonenumber'] = $user->getTelephonenumber();
|
||||
$output['useravatar'] = 'https://'.str_replace('//', '/', $this->getParameter('appWeburl').$this->getParameter('appAlias').$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$user->getAvatar()], true));
|
||||
$output['userniveau01'] = $this->niveau01Format($user->getNiveau01());
|
||||
$output['userniveau02'] = $this->niveau02Format($user->getNiveau02());
|
||||
$output['usergroups'] = [];
|
||||
foreach ($user->getGroups() as $usergroup) {
|
||||
$groupFormat = $this->groupFormat($usergroup->getGroup());
|
||||
if ($groupFormat) {
|
||||
array_push($output['usergroups'], $groupFormat);
|
||||
}
|
||||
if(empty($output["niveau01users"])) $output["niveau01users"]=null;
|
||||
}
|
||||
if (empty($output['usergroups'])) {
|
||||
$output['usergroups'] = null;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function niveau02Format($niveau02,$withmembers=false){
|
||||
if(!$niveau02) return null;
|
||||
$output=[];
|
||||
$output["niveau02id"]=$niveau02->getId();
|
||||
$output["niveau02label"]=$niveau02->getLabel();
|
||||
private function niveau01Format($niveau01, $withmembers = false)
|
||||
{
|
||||
if (!$niveau01) {
|
||||
return null;
|
||||
}
|
||||
$output = [];
|
||||
$output['niveau01id'] = $niveau01->getId();
|
||||
$output['niveau01label'] = $niveau01->getLabel();
|
||||
|
||||
if($withmembers) {
|
||||
$output["niveau02niveau01"]=$this->niveau01Format($niveau02->getNiveau01());
|
||||
$output["niveau02users"]=[];
|
||||
foreach($niveau02->getUsers() as $user) {
|
||||
array_push($output["niveau02users"],["userid"=>$user->getId(),"userlogin"=>$user->getUsername()]);
|
||||
if ($withmembers) {
|
||||
$output['niveau01users'] = [];
|
||||
foreach ($niveau01->getUsers() as $user) {
|
||||
array_push($output['niveau01users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]);
|
||||
}
|
||||
if (empty($output['niveau01users'])) {
|
||||
$output['niveau01users'] = null;
|
||||
}
|
||||
if(empty($output["niveau02users"])) $output["niveau02users"]=null;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function groupFormat($group,$withmembers=false){
|
||||
if(!$group||$group->getId()<0) return null;
|
||||
$output=[];
|
||||
$output["groupid"]=$group->getId();
|
||||
$output["grouplabel"]=$group->getLabel();
|
||||
private function niveau02Format($niveau02, $withmembers = false)
|
||||
{
|
||||
if (!$niveau02) {
|
||||
return null;
|
||||
}
|
||||
$output = [];
|
||||
$output['niveau02id'] = $niveau02->getId();
|
||||
$output['niveau02label'] = $niveau02->getLabel();
|
||||
|
||||
if($withmembers) {
|
||||
$output["groupusers"]=[];
|
||||
foreach($group->getUsers() as $usergroup) {
|
||||
array_push($output["groupusers"],["userid"=>$usergroup->getUser()->getId(),"userlogin"=>$usergroup->getUser()->getUsername()]);
|
||||
if ($withmembers) {
|
||||
$output['niveau02niveau01'] = $this->niveau01Format($niveau02->getNiveau01());
|
||||
$output['niveau02users'] = [];
|
||||
foreach ($niveau02->getUsers() as $user) {
|
||||
array_push($output['niveau02users'], ['userid' => $user->getId(), 'userlogin' => $user->getUsername()]);
|
||||
}
|
||||
if (empty($output['niveau02users'])) {
|
||||
$output['niveau02users'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function groupFormat($group, $withmembers = false)
|
||||
{
|
||||
if (!$group || $group->getId() < 0) {
|
||||
return null;
|
||||
}
|
||||
$output = [];
|
||||
$output['groupid'] = $group->getId();
|
||||
$output['grouplabel'] = $group->getLabel();
|
||||
|
||||
if ($withmembers) {
|
||||
$output['groupusers'] = [];
|
||||
foreach ($group->getUsers() as $usergroup) {
|
||||
array_push($output['groupusers'], ['userid' => $usergroup->getUser()->getId(), 'userlogin' => $usergroup->getUser()->getUsername()]);
|
||||
}
|
||||
if (empty($output['groupusers'])) {
|
||||
$output['groupusers'] = null;
|
||||
}
|
||||
if(empty($output["groupusers"])) $output["groupusers"]=null;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,524 +1,574 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Niveau01;
|
||||
use App\Entity\Group;
|
||||
use App\Form\LoginType;
|
||||
use App\Service\LdapService;
|
||||
use App\Service\ApiService;
|
||||
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
private $appKernel;
|
||||
private $tokenstorage;
|
||||
private $ldapservice;
|
||||
private $apiservice;
|
||||
|
||||
public function __construct(KernelInterface $appKernel, TokenStorageInterface $tokenstorage, LdapService $ldapservice, ApiService $apiservice)
|
||||
{
|
||||
$this->appKernel = $appKernel;
|
||||
$this->tokenstorage = $tokenstorage;
|
||||
$this->ldapservice = $ldapservice;
|
||||
$this->apiservice = $apiservice;
|
||||
}
|
||||
|
||||
public function noperm(Request $request)
|
||||
{
|
||||
return $this->render('Home/noperm.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function login(Request $request, AuthenticationUtils $authenticationUtils,ManagerRegistry $em)
|
||||
{
|
||||
switch($this->getParameter("appAuth")) {
|
||||
case "SQL":
|
||||
return $this->loginSQL($request,$authenticationUtils,$em);
|
||||
break;
|
||||
|
||||
case "CAS":
|
||||
return $this->loginCAS($request,$authenticationUtils,$em);
|
||||
break;
|
||||
|
||||
case "LDAP":
|
||||
return $this->loginLDAP($request,$authenticationUtils,$em);
|
||||
break;
|
||||
|
||||
case "OPENID":
|
||||
return $this->loginOPENID($request,$authenticationUtils,$em);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function loginSQL(Request $request, AuthenticationUtils $authenticationUtils,ManagerRegistry $em)
|
||||
{
|
||||
return $this->render('Home/loginSQL.html.twig', array(
|
||||
'last_username' => $authenticationUtils->getLastUsername(),
|
||||
'error' => $authenticationUtils->getLastAuthenticationError(),
|
||||
));
|
||||
}
|
||||
|
||||
public function loginCAS(Request $request, AuthenticationUtils $authenticationUtils,ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de la cible de navigation
|
||||
$redirect = $request->getSession()->get("_security.main.target_path");
|
||||
|
||||
// Masteridentity
|
||||
$appMasteridentity=$this->getParameter("appMasteridentity");
|
||||
|
||||
// Init Client CAS
|
||||
$alias=$this->getParameter('appAlias');
|
||||
\phpCAS::setDebug($this->appKernel->getProjectDir()."/var/log/cas.log");
|
||||
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
|
||||
\phpCAS::setNoCasServerValidation();
|
||||
|
||||
|
||||
// Authentification
|
||||
\phpCAS::forceAuthentication();
|
||||
|
||||
// Récupération UID
|
||||
$username = \phpCAS::getUser();
|
||||
|
||||
// Récupération Attribut
|
||||
$attributes = \phpCAS::getAttributes();
|
||||
|
||||
// Init
|
||||
$email = "$username@nomail.fr";
|
||||
$lastname = $username;
|
||||
$firstname = " ";
|
||||
$avatar="noavatar.png";
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
if(isset($attributes[$this->getParameter('casUsername')]))
|
||||
$username = $attributes[$this->getParameter('casUsername')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casEmail')]))
|
||||
$email = $attributes[$this->getParameter('casEmail')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casLastname')]))
|
||||
$lastname = $attributes[$this->getParameter('casLastname')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casFirstname')]))
|
||||
$firstname = $attributes[$this->getParameter('casFirstname')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('casAvatar')]))
|
||||
$avatar = $attributes[$this->getParameter('casAvatar')];
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
$user = $em->getRepository('App\Entity\User')->findOneBy(array("username"=>$username));
|
||||
if (!$user) {
|
||||
if(!$this->getParameter("casAutosubmit")) return $this->redirect($this->generateUrl('app_noperm'));
|
||||
|
||||
$this->submitSSONiveau01($attributes,$em);
|
||||
$this->submitSSOGroup($attributes,$em);
|
||||
$niveau01=$em->getRepository('App\Entity\Niveau01')->calculateSSONiveau01($attributes);
|
||||
$user=$this->submituser($username,$firstname,$lastname,$email,$avatar,$niveau01,$em);
|
||||
$user=$em->getRepository('App\Entity\Group')->calculateSSOGroup($user,$attributes);
|
||||
}
|
||||
elseif($this->getParameter("casAutoupdate")) {
|
||||
$this->submitSSONiveau01($attributes,$em);
|
||||
$this->submitSSOGroup($attributes,$em);
|
||||
$this->updateuser($user,$firstname,$lastname,$email,$avatar,$em);
|
||||
$user=$em->getRepository('App\Entity\Group')->calculateSSOGroup($user,$attributes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Autoconnexion
|
||||
return $this->autoconnexion($user,$redirect,$request);
|
||||
}
|
||||
|
||||
public function loginLDAP(Request $request, AuthenticationUtils $authenticationUtils,ManagerRegistry $em)
|
||||
{
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(LoginType::class);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render("Home/loginLDAP.html.twig", [
|
||||
"useheader"=>false,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>false,
|
||||
"form"=>$form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function loginldapcheck(Request $request, AuthenticationUtils $authenticationUtils,ManagerRegistry $em)
|
||||
{
|
||||
|
||||
$username=$request->get('login')["username"];
|
||||
$password=$request->get('login')["password"];
|
||||
|
||||
// Récupération de la cible de navigation
|
||||
$redirect = $request->getSession()->get("_security.main.target_path");
|
||||
|
||||
// L'utilisateur se co à l'annuaire
|
||||
$userldap=$this->ldapservice->userconnect($username,$password);
|
||||
if($userldap) {
|
||||
$userldap=$userldap[0];
|
||||
|
||||
// Init
|
||||
$email = "$username@nomail.fr";
|
||||
$lastname = $username;
|
||||
$firstname = " ";
|
||||
$avatar="noavatar.png";
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
if(isset($userldap[$this->getParameter('ldapFirstname')]))
|
||||
$firstname = $userldap[$this->getParameter('ldapFirstname')];
|
||||
|
||||
if(isset($userldap[$this->getParameter('ldapLastname')]))
|
||||
$lastname = $userldap[$this->getParameter('ldapLastname')];
|
||||
|
||||
if(isset($userldap[$this->getParameter('ldapEmail')]))
|
||||
$email = $userldap[$this->getParameter('ldapEmail')];
|
||||
|
||||
if(isset($userldap[$this->getParameter('ldapAvatar')]))
|
||||
$avatar = $userldap[$this->getParameter('ldapAvatar')];
|
||||
|
||||
$user = $em->getRepository('App\Entity\User')->findOneBy(array("username"=>$username));
|
||||
|
||||
if (!$user) {
|
||||
if(!$this->getParameter("ldapAutosubmit")) return $this->redirect($this->generateUrl('app_noperm'));
|
||||
$niveau01=$em->getRepository('App\Entity\Niveau01')->calculateLDAPNiveau01($username);
|
||||
$user=$this->submituser($username,$firstname,$lastname,$email,$avatar,$niveau01,$em);
|
||||
}
|
||||
elseif($this->getParameter("ldapAutoupdate")) {
|
||||
$this->updateuser($user,$firstname,$lastname,$email,$avatar,$em);
|
||||
}
|
||||
|
||||
// Autoconnexion
|
||||
return $this->autoconnexion($user,$redirect,$request);
|
||||
}
|
||||
|
||||
return $this->redirect($this->generateUrl('app_login'));
|
||||
}
|
||||
|
||||
|
||||
public function loginOPENID(Request $request, AuthenticationUtils $authenticationUtils,ManagerRegistry $em)
|
||||
{
|
||||
$state=Uuid::uuid4();
|
||||
$request->getSession()->set("oauthState",$state);
|
||||
$callback=$this->generateUrl('app_loginopenidcallback', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$url=$this->getParameter("oauthLoginurl")."?client_id=".$this->getParameter("oauthClientid")."&redirect_uri=".$callback."&response_type=code&state=".$state."&scope=openid";
|
||||
return $this->redirect($url);
|
||||
}
|
||||
|
||||
public function loginopenidcallback(Request $request, AuthenticationUtils $authenticationUtils,ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de la cible de navigation
|
||||
$redirect = $request->getSession()->get("_security.main.target_path");
|
||||
|
||||
// Masteridentity
|
||||
$appMasteridentity=$this->getParameter("appMasteridentity");
|
||||
|
||||
$callback=$this->generateUrl('app_loginopenidcallback', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$apiurl = $this->getParameter("oauthTokenurl");
|
||||
$query= [
|
||||
"grant_type" => "authorization_code",
|
||||
"code" => $request->get("code"),
|
||||
"redirect_uri" => $callback,
|
||||
"client_id" => $this->getParameter("oauthClientid"),
|
||||
"client_secret" => $this->getParameter("oauthClientsecret"),
|
||||
];
|
||||
$response=$this->apiservice->run("POST",$apiurl,$query,null,"form");
|
||||
|
||||
if(!$response||$response->code!="200") die("pb openid 01");
|
||||
$accesstoken=$response->body->access_token;
|
||||
$accesstokentype=$response->body->token_type;
|
||||
$îdtoken=$response->body->id_token;
|
||||
|
||||
$request->getSession()->set("oauthAccesstoken",$accesstoken);
|
||||
$request->getSession()->set("oauthIdtoken",$îdtoken);
|
||||
|
||||
$apiurl = $this->getParameter("oauthUserinfo");
|
||||
|
||||
$response=$this->apiservice->run("GET",$apiurl,null,["Authorization"=>$accesstokentype." ".$accesstoken]);
|
||||
if(!$response||$response->code!="200") die("pb openid 02");
|
||||
|
||||
$attributes=json_decode(json_encode($response->body), true);
|
||||
|
||||
// Username
|
||||
$username="";
|
||||
if(isset($attributes[$this->getParameter('oauthUsername')]))
|
||||
$username = $attributes[$this->getParameter('oauthUsername')];
|
||||
|
||||
// Valeur par défaut
|
||||
$email = "$username@nomail.fr";
|
||||
$lastname = $username;
|
||||
$firstname = " ";
|
||||
$avatar="noavatar.png";
|
||||
|
||||
// Récupérer les attributs associés
|
||||
if(isset($attributes[$this->getParameter('oauthEmail')]))
|
||||
$email = $attributes[$this->getParameter('oauthEmail')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('oauthLastname')]))
|
||||
$lastname = $attributes[$this->getParameter('oauthLastname')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('oauthFirstname')]))
|
||||
$firstname = $attributes[$this->getParameter('oauthFirstname')];
|
||||
|
||||
if(isset($attributes[$this->getParameter('oauthAvatar')]))
|
||||
$avatar = $attributes[$this->getParameter('oauthAvatar')];
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
$user = $em->getRepository('App\Entity\User')->findOneBy(array("username"=>$username));
|
||||
if (!$user) {
|
||||
if(!$this->getParameter("oauthAutosubmit")) return $this->redirect($this->generateUrl('app_noperm'));
|
||||
|
||||
$this->submitSSONiveau01($attributes,$em);
|
||||
$this->submitSSOGroup($attributes,$em);
|
||||
$niveau01=$em->getRepository('App\Entity\Niveau01')->calculateSSONiveau01($attributes);
|
||||
$user=$this->submituser($username,$firstname,$lastname,$email,$avatar,$niveau01,$em);
|
||||
}
|
||||
elseif($this->getParameter("oauthAutoupdate")) {
|
||||
$this->submitSSONiveau01($attributes,$em);
|
||||
$this->submitSSOGroup($attributes,$em);
|
||||
$this->updateuser($user,$firstname,$lastname,$email,$avatar,$em);
|
||||
$user=$em->getRepository('App\Entity\Group')->calculateSSOGroup($user,$attributes);
|
||||
}
|
||||
|
||||
// Autoconnexion
|
||||
return $this->autoconnexion($user,$redirect,$request);
|
||||
}
|
||||
|
||||
public function logout(Request $request) {
|
||||
$auth_mode=$this->getParameter("appAuth");
|
||||
switch($auth_mode) {
|
||||
case "SQL":
|
||||
return $this->logoutSQL($request);
|
||||
break;
|
||||
|
||||
case "CAS":
|
||||
return $this->logoutCAS($request);
|
||||
break;
|
||||
|
||||
case "LDAP":
|
||||
return $this->logoutLDAP($request);
|
||||
break;
|
||||
|
||||
case "OPENID":
|
||||
return $this->logoutOPENID($request);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function logoutSQL(Request $request) {
|
||||
$this->tokenstorage->setToken(null);
|
||||
$request->getSession()->invalidate();
|
||||
return $this->redirect($this->generateUrl("app_home"));
|
||||
}
|
||||
|
||||
public function logoutCAS(Request $request) {
|
||||
$this->tokenstorage->setToken(null);
|
||||
$request->getSession()->invalidate();
|
||||
|
||||
// Init Client CAS
|
||||
$alias=$this->getParameter('appAlias');
|
||||
\phpCAS::setDebug($this->appKernel->getProjectDir()."/var/log/cas.log");
|
||||
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
|
||||
\phpCAS::setNoCasServerValidation();
|
||||
|
||||
|
||||
// Logout
|
||||
$url=$this->generateUrl('app_home', array(), UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
\phpCAS::logout(array("service"=>$url));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function logoutLDAP(Request $request) {
|
||||
$this->tokenstorage->setToken(null);
|
||||
$request->getSession()->invalidate();
|
||||
return $this->redirect($this->generateUrl("app_home"));
|
||||
}
|
||||
|
||||
|
||||
public function logoutOPENID(Request $request) {
|
||||
$accesstoken=$request->getSession()->get("oauthAccesstoken");
|
||||
$idtoken=$request->getSession()->get("oauthIdtoken");
|
||||
$state=$request->getSession()->get("oauthState");
|
||||
|
||||
$this->tokenstorage->setToken(null);
|
||||
$request->getSession()->invalidate();
|
||||
|
||||
$url=$this->getParameter("oauthLogouturl");
|
||||
if($url) {
|
||||
$callback=($request->isSecure()?"https://":"http://").str_replace("//","/",$this->getParameter("appWeburl").$this->getParameter("appAlias").$this->generateUrl('app_home'));
|
||||
$callback=substr($callback, 0, -1);
|
||||
|
||||
$url.="?id_token_hint=$idtoken&scope=openid&post_logout_redirect_uri=$callback";
|
||||
return $this->redirect($url);
|
||||
|
||||
} else return $this->redirect($this->generateUrl("app_home"));
|
||||
}
|
||||
|
||||
// Génération automatique des niveau01 provenant de l'attribut casniveau01
|
||||
private function submitSSONiveau01($attributes,ManagerRegistry $em) {
|
||||
$attrNiveau01=($this->getParameter("appAuth")=="CAS"?$this->getParameter('casNiveau01'):$this->getParameter('oauthNiveau01'));
|
||||
if(!$attrNiveau01)
|
||||
return null;
|
||||
|
||||
// Si l'utilisateur possège l'attribut niveau01 dans ses attributs
|
||||
if(array_key_exists($attrNiveau01,$attributes)) {
|
||||
if(!is_array($attributes[$attrNiveau01])) {
|
||||
$attributes[$attrNiveau01]=[$attributes[$attrNiveau01]];
|
||||
}
|
||||
|
||||
foreach($attributes[$attrNiveau01] as $ssoniveau01) {
|
||||
$basedn=$this->getParameter('ldapBasedn');
|
||||
$name=$ssoniveau01;
|
||||
if($basedn!="") {
|
||||
// Si présence du basedn dans le nom du groupe = nous sommes en présence d'un DN = on récupere donc comme nom que son cn
|
||||
if(stripos($name,$basedn)!==false) {
|
||||
$tbname=explode(",",$name);
|
||||
$tbname=explode("=",$tbname[0]);
|
||||
$name=$tbname[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Recherche du groupe
|
||||
$niveau01=$em->getRepository("App\Entity\Niveau01")->findOneBy(["label"=>$name]);
|
||||
if(!$niveau01) {
|
||||
$niveau01=new Niveau01();
|
||||
$niveau01->setLabel($name);
|
||||
$niveau01->setApikey(Uuid::uuid4());
|
||||
}
|
||||
|
||||
$niveau01->setAttributes('{"'.$attrNiveau01.'":"'.$ssoniveau01.'"}');
|
||||
$em->getManager()->persist($niveau01);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Génération automatique des groupes provenant de l'attribut casgroup ou oauthgroup
|
||||
private function submitSSOGroup($attributes,ManagerRegistry $em) {
|
||||
$attrGroup=($this->getParameter("appAuth")=="CAS"?$this->getParameter('casGroup'):$this->getParameter('oauthGroup'));
|
||||
if(!$attrGroup)
|
||||
return null;
|
||||
|
||||
// Si l'utilisateur possège l'attribut groupe dans ses attributs
|
||||
if(array_key_exists($attrGroup,$attributes)) {
|
||||
if(!is_array($attributes[$attrGroup])) {
|
||||
$attributes[$attrGroup]=[$attributes[$attrGroup]];
|
||||
}
|
||||
|
||||
foreach($attributes[$attrGroup] as $ssogroup) {
|
||||
$basedn=$this->getParameter('ldapBasedn');
|
||||
$name=$ssogroup;
|
||||
if($basedn!="") {
|
||||
// Si présence du basedn dans le nom du groupe = nous sommes en présence d'un DN = on récupere donc comme nom que son cn
|
||||
if(stripos($name,$basedn)!==false) {
|
||||
$tbname=explode(",",$name);
|
||||
$tbname=explode("=",$tbname[0]);
|
||||
$name=$tbname[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Recherche du groupe
|
||||
$group=$em->getRepository("App\Entity\Group")->findOneBy(["label"=>$name]);
|
||||
if(!$group) {
|
||||
$group=new Group();
|
||||
$group->setLabel($name);
|
||||
$group->setIsopen(false);
|
||||
$group->setIsworkgroup(false);
|
||||
$group->setApikey(Uuid::uuid4());
|
||||
}
|
||||
|
||||
$group->setAttributes('{"'.$attrGroup.'":"'.$ssogroup.'"}');
|
||||
$em->getManager()->persist($group);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function submituser($username,$firstname,$lastname,$email,$avatar,$niveau01,$em) {
|
||||
if(empty($email)) $email = $username."@nomail.com";
|
||||
if(empty($avatar)) $avatar = "noavatar.png";
|
||||
if(empty($firstname)) $firstname = " ";
|
||||
if(empty($lastname)) $lastname = $username;
|
||||
$uuid=Uuid::uuid4();
|
||||
$password=$this->getParameter("appAuth")."PWD-".$username."-".$uuid;
|
||||
|
||||
// Si aucun niveau01 on prend par défaut le niveau system
|
||||
if(!$niveau01) $niveau01=$em->getRepository('App\Entity\Niveau01')->find(-1);
|
||||
|
||||
// Autogénération du user vu qu'il a pu se connecter
|
||||
$user = new User();
|
||||
|
||||
$user->setUsername($username);
|
||||
$user->setEmail($email);
|
||||
$user->setLastname($lastname);
|
||||
$user->setFirstname($firstname);
|
||||
$user->setApikey(Uuid::uuid4());
|
||||
|
||||
$user->setPassword($password);
|
||||
$user->setNiveau01($niveau01);
|
||||
|
||||
$user->setAvatar($avatar);
|
||||
$user->setIsvisible(true);
|
||||
$user->setRole("ROLE_USER");
|
||||
|
||||
if(in_array($username,$this->getParameter("appAdmins")))
|
||||
$user->setRole("ROLE_ADMIN");
|
||||
|
||||
$em->getManager()->persist($user);
|
||||
$em->getManager()->flush();
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function updateuser($user,$firstname,$lastname,$email,$avatar,$em) {
|
||||
if($avatar=="noavatar.png") $avatar=$user->getAvatar();
|
||||
|
||||
if(!empty($lastname)) $user->setLastname($lastname);
|
||||
if(!empty($firstname)) $user->setFirstname($firstname);
|
||||
if(!empty($email)) $user->setEmail($email);
|
||||
if(!empty($avatar)) $user->setAvatar($avatar);
|
||||
|
||||
if(in_array($user->getUsername(),$this->getParameter("appAdmins")))
|
||||
$user->setRole("ROLE_ADMIN");
|
||||
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
|
||||
private function autoconnexion($user,$redirect,Request $request)
|
||||
{
|
||||
// Récupérer le token de l'utilisateur
|
||||
$token = new UsernamePasswordToken($user, "main", $user->getRoles());
|
||||
$this->tokenstorage->setToken($token);
|
||||
$request->getSession()->set('_security_main', serialize($token));
|
||||
|
||||
// Simuler l'evenement de connexion
|
||||
$event = new InteractiveLoginEvent($request, $token);
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->dispatch($event);
|
||||
|
||||
// Redirection
|
||||
if($redirect)
|
||||
return $this->redirect($redirect);
|
||||
else
|
||||
return $this->redirect($this->generateUrl('app_home'));
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Group;
|
||||
use App\Entity\Niveau01;
|
||||
use App\Entity\User;
|
||||
use App\Form\LoginType;
|
||||
use App\Service\ApiService;
|
||||
use App\Service\LdapService;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
|
||||
|
||||
class SecurityController extends AbstractController
|
||||
{
|
||||
private $appKernel;
|
||||
private $tokenstorage;
|
||||
private $ldapservice;
|
||||
private $apiservice;
|
||||
|
||||
public function __construct(KernelInterface $appKernel, TokenStorageInterface $tokenstorage, LdapService $ldapservice, ApiService $apiservice)
|
||||
{
|
||||
$this->appKernel = $appKernel;
|
||||
$this->tokenstorage = $tokenstorage;
|
||||
$this->ldapservice = $ldapservice;
|
||||
$this->apiservice = $apiservice;
|
||||
}
|
||||
|
||||
public function noperm(Request $request)
|
||||
{
|
||||
return $this->render('Home/noperm.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function login(Request $request, AuthenticationUtils $authenticationUtils, ManagerRegistry $em)
|
||||
{
|
||||
switch ($this->getParameter('appAuth')) {
|
||||
case 'SQL':
|
||||
return $this->loginSQL($request, $authenticationUtils, $em);
|
||||
break;
|
||||
|
||||
case 'CAS':
|
||||
return $this->loginCAS($request, $authenticationUtils, $em);
|
||||
break;
|
||||
|
||||
case 'LDAP':
|
||||
return $this->loginLDAP($request, $authenticationUtils, $em);
|
||||
break;
|
||||
|
||||
case 'OPENID':
|
||||
return $this->loginOPENID($request, $authenticationUtils, $em);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function loginSQL(Request $request, AuthenticationUtils $authenticationUtils, ManagerRegistry $em)
|
||||
{
|
||||
return $this->render('Home/loginSQL.html.twig', [
|
||||
'last_username' => $authenticationUtils->getLastUsername(),
|
||||
'error' => $authenticationUtils->getLastAuthenticationError(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function loginCAS(Request $request, AuthenticationUtils $authenticationUtils, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de la cible de navigation
|
||||
$redirect = $request->getSession()->get('_security.main.target_path');
|
||||
|
||||
// Masteridentity
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
|
||||
// Init Client CAS
|
||||
$alias = $this->getParameter('appAlias');
|
||||
\phpCAS::setDebug($this->appKernel->getProjectDir().'/var/log/cas.log');
|
||||
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
|
||||
\phpCAS::setNoCasServerValidation();
|
||||
|
||||
// Authentification
|
||||
\phpCAS::forceAuthentication();
|
||||
|
||||
// Récupération UID
|
||||
$username = \phpCAS::getUser();
|
||||
|
||||
// Récupération Attribut
|
||||
$attributes = \phpCAS::getAttributes();
|
||||
|
||||
// Init
|
||||
$email = "$username@nomail.fr";
|
||||
$lastname = $username;
|
||||
$firstname = ' ';
|
||||
$avatar = 'noavatar.png';
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
if (isset($attributes[$this->getParameter('casUsername')])) {
|
||||
$username = $attributes[$this->getParameter('casUsername')];
|
||||
}
|
||||
|
||||
if (isset($attributes[$this->getParameter('casEmail')])) {
|
||||
$email = $attributes[$this->getParameter('casEmail')];
|
||||
}
|
||||
|
||||
if (isset($attributes[$this->getParameter('casLastname')])) {
|
||||
$lastname = $attributes[$this->getParameter('casLastname')];
|
||||
}
|
||||
|
||||
if (isset($attributes[$this->getParameter('casFirstname')])) {
|
||||
$firstname = $attributes[$this->getParameter('casFirstname')];
|
||||
}
|
||||
|
||||
if (isset($attributes[$this->getParameter('casAvatar')])) {
|
||||
$avatar = $attributes[$this->getParameter('casAvatar')];
|
||||
}
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
$user = $em->getRepository('App\Entity\User')->findOneBy(['username' => $username]);
|
||||
if (!$user) {
|
||||
if (!$this->getParameter('casAutosubmit')) {
|
||||
return $this->redirect($this->generateUrl('app_noperm'));
|
||||
}
|
||||
|
||||
$this->submitSSONiveau01($attributes, $em);
|
||||
$this->submitSSOGroup($attributes, $em);
|
||||
$niveau01 = $em->getRepository('App\Entity\Niveau01')->calculateSSONiveau01($attributes);
|
||||
$user = $this->submituser($username, $firstname, $lastname, $email, $avatar, $niveau01, $em);
|
||||
$user = $em->getRepository('App\Entity\Group')->calculateSSOGroup($user, $attributes);
|
||||
} elseif ($this->getParameter('casAutoupdate')) {
|
||||
$this->submitSSONiveau01($attributes, $em);
|
||||
$this->submitSSOGroup($attributes, $em);
|
||||
$this->updateuser($user, $firstname, $lastname, $email, $avatar, $em);
|
||||
$user = $em->getRepository('App\Entity\Group')->calculateSSOGroup($user, $attributes);
|
||||
}
|
||||
|
||||
// Autoconnexion
|
||||
return $this->autoconnexion($user, $redirect, $request);
|
||||
}
|
||||
|
||||
public function loginLDAP(Request $request, AuthenticationUtils $authenticationUtils, ManagerRegistry $em)
|
||||
{
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(LoginType::class);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render('Home/loginLDAP.html.twig', [
|
||||
'useheader' => false,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => false,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function loginldapcheck(Request $request, AuthenticationUtils $authenticationUtils, ManagerRegistry $em)
|
||||
{
|
||||
$username = $request->get('login')['username'];
|
||||
$password = $request->get('login')['password'];
|
||||
|
||||
// Récupération de la cible de navigation
|
||||
$redirect = $request->getSession()->get('_security.main.target_path');
|
||||
|
||||
// L'utilisateur se co à l'annuaire
|
||||
$userldap = $this->ldapservice->userconnect($username, $password);
|
||||
if ($userldap) {
|
||||
$userldap = $userldap[0];
|
||||
|
||||
// Init
|
||||
$email = "$username@nomail.fr";
|
||||
$lastname = $username;
|
||||
$firstname = ' ';
|
||||
$avatar = 'noavatar.png';
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
if (isset($userldap[$this->getParameter('ldapFirstname')])) {
|
||||
$firstname = $userldap[$this->getParameter('ldapFirstname')];
|
||||
}
|
||||
|
||||
if (isset($userldap[$this->getParameter('ldapLastname')])) {
|
||||
$lastname = $userldap[$this->getParameter('ldapLastname')];
|
||||
}
|
||||
|
||||
if (isset($userldap[$this->getParameter('ldapEmail')])) {
|
||||
$email = $userldap[$this->getParameter('ldapEmail')];
|
||||
}
|
||||
|
||||
if (isset($userldap[$this->getParameter('ldapAvatar')])) {
|
||||
$avatar = $userldap[$this->getParameter('ldapAvatar')];
|
||||
}
|
||||
|
||||
$user = $em->getRepository('App\Entity\User')->findOneBy(['username' => $username]);
|
||||
|
||||
if (!$user) {
|
||||
if (!$this->getParameter('ldapAutosubmit')) {
|
||||
return $this->redirect($this->generateUrl('app_noperm'));
|
||||
}
|
||||
$niveau01 = $em->getRepository('App\Entity\Niveau01')->calculateLDAPNiveau01($username);
|
||||
$user = $this->submituser($username, $firstname, $lastname, $email, $avatar, $niveau01, $em);
|
||||
} elseif ($this->getParameter('ldapAutoupdate')) {
|
||||
$this->updateuser($user, $firstname, $lastname, $email, $avatar, $em);
|
||||
}
|
||||
|
||||
// Autoconnexion
|
||||
return $this->autoconnexion($user, $redirect, $request);
|
||||
}
|
||||
|
||||
return $this->redirect($this->generateUrl('app_login'));
|
||||
}
|
||||
|
||||
public function loginOPENID(Request $request, AuthenticationUtils $authenticationUtils, ManagerRegistry $em)
|
||||
{
|
||||
$state = Uuid::uuid4();
|
||||
$request->getSession()->set('oauthState', $state);
|
||||
$callback = $this->generateUrl('app_loginopenidcallback', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$url = $this->getParameter('oauthLoginurl').'?client_id='.$this->getParameter('oauthClientid').'&redirect_uri='.$callback.'&response_type=code&state='.$state.'&scope=openid';
|
||||
|
||||
return $this->redirect($url);
|
||||
}
|
||||
|
||||
public function loginopenidcallback(Request $request, AuthenticationUtils $authenticationUtils, ManagerRegistry $em)
|
||||
{
|
||||
// Récupération de la cible de navigation
|
||||
$redirect = $request->getSession()->get('_security.main.target_path');
|
||||
|
||||
// Masteridentity
|
||||
$appMasteridentity = $this->getParameter('appMasteridentity');
|
||||
|
||||
$callback = $this->generateUrl('app_loginopenidcallback', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
$apiurl = $this->getParameter('oauthTokenurl');
|
||||
$query = [
|
||||
'grant_type' => 'authorization_code',
|
||||
'code' => $request->get('code'),
|
||||
'redirect_uri' => $callback,
|
||||
'client_id' => $this->getParameter('oauthClientid'),
|
||||
'client_secret' => $this->getParameter('oauthClientsecret'),
|
||||
];
|
||||
$response = $this->apiservice->run('POST', $apiurl, $query, null, 'form');
|
||||
|
||||
if (!$response || '200' != $response->code) {
|
||||
exit('pb openid 01');
|
||||
}
|
||||
$accesstoken = $response->body->access_token;
|
||||
$accesstokentype = $response->body->token_type;
|
||||
$îdtoken = $response->body->id_token;
|
||||
|
||||
$request->getSession()->set('oauthAccesstoken', $accesstoken);
|
||||
$request->getSession()->set('oauthIdtoken', $îdtoken);
|
||||
|
||||
$apiurl = $this->getParameter('oauthUserinfo');
|
||||
|
||||
$response = $this->apiservice->run('GET', $apiurl, null, ['Authorization' => $accesstokentype.' '.$accesstoken]);
|
||||
if (!$response || '200' != $response->code) {
|
||||
exit('pb openid 02');
|
||||
}
|
||||
|
||||
$attributes = json_decode(json_encode($response->body), true);
|
||||
|
||||
// Username
|
||||
$username = '';
|
||||
if (isset($attributes[$this->getParameter('oauthUsername')])) {
|
||||
$username = $attributes[$this->getParameter('oauthUsername')];
|
||||
}
|
||||
|
||||
// Valeur par défaut
|
||||
$email = "$username@nomail.fr";
|
||||
$lastname = $username;
|
||||
$firstname = ' ';
|
||||
$avatar = 'noavatar.png';
|
||||
|
||||
// Récupérer les attributs associés
|
||||
if (isset($attributes[$this->getParameter('oauthEmail')])) {
|
||||
$email = $attributes[$this->getParameter('oauthEmail')];
|
||||
}
|
||||
|
||||
if (isset($attributes[$this->getParameter('oauthLastname')])) {
|
||||
$lastname = $attributes[$this->getParameter('oauthLastname')];
|
||||
}
|
||||
|
||||
if (isset($attributes[$this->getParameter('oauthFirstname')])) {
|
||||
$firstname = $attributes[$this->getParameter('oauthFirstname')];
|
||||
}
|
||||
|
||||
if (isset($attributes[$this->getParameter('oauthAvatar')])) {
|
||||
$avatar = $attributes[$this->getParameter('oauthAvatar')];
|
||||
}
|
||||
|
||||
// Rechercher l'utilisateur
|
||||
$user = $em->getRepository('App\Entity\User')->findOneBy(['username' => $username]);
|
||||
if (!$user) {
|
||||
if (!$this->getParameter('oauthAutosubmit')) {
|
||||
return $this->redirect($this->generateUrl('app_noperm'));
|
||||
}
|
||||
|
||||
$this->submitSSONiveau01($attributes, $em);
|
||||
$this->submitSSOGroup($attributes, $em);
|
||||
$niveau01 = $em->getRepository('App\Entity\Niveau01')->calculateSSONiveau01($attributes);
|
||||
$user = $this->submituser($username, $firstname, $lastname, $email, $avatar, $niveau01, $em);
|
||||
} elseif ($this->getParameter('oauthAutoupdate')) {
|
||||
$this->submitSSONiveau01($attributes, $em);
|
||||
$this->submitSSOGroup($attributes, $em);
|
||||
$this->updateuser($user, $firstname, $lastname, $email, $avatar, $em);
|
||||
$user = $em->getRepository('App\Entity\Group')->calculateSSOGroup($user, $attributes);
|
||||
}
|
||||
|
||||
// Autoconnexion
|
||||
return $this->autoconnexion($user, $redirect, $request);
|
||||
}
|
||||
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$auth_mode = $this->getParameter('appAuth');
|
||||
switch ($auth_mode) {
|
||||
case 'SQL':
|
||||
return $this->logoutSQL($request);
|
||||
break;
|
||||
|
||||
case 'CAS':
|
||||
return $this->logoutCAS($request);
|
||||
break;
|
||||
|
||||
case 'LDAP':
|
||||
return $this->logoutLDAP($request);
|
||||
break;
|
||||
|
||||
case 'OPENID':
|
||||
return $this->logoutOPENID($request);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function logoutSQL(Request $request)
|
||||
{
|
||||
$this->tokenstorage->setToken(null);
|
||||
$request->getSession()->invalidate();
|
||||
|
||||
return $this->redirect($this->generateUrl('app_home'));
|
||||
}
|
||||
|
||||
public function logoutCAS(Request $request)
|
||||
{
|
||||
$this->tokenstorage->setToken(null);
|
||||
$request->getSession()->invalidate();
|
||||
|
||||
// Init Client CAS
|
||||
$alias = $this->getParameter('appAlias');
|
||||
\phpCAS::setDebug($this->appKernel->getProjectDir().'/var/log/cas.log');
|
||||
\phpCAS::client(CAS_VERSION_2_0, $this->getParameter('casHost'), intval($this->getParameter('casPort')), is_null($this->getParameter('casPath')) ? '' : $this->getParameter('casPath'), false);
|
||||
\phpCAS::setNoCasServerValidation();
|
||||
|
||||
// Logout
|
||||
$url = $this->generateUrl('app_home', [], UrlGeneratorInterface::ABSOLUTE_URL);
|
||||
\phpCAS::logout(['service' => $url]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function logoutLDAP(Request $request)
|
||||
{
|
||||
$this->tokenstorage->setToken(null);
|
||||
$request->getSession()->invalidate();
|
||||
|
||||
return $this->redirect($this->generateUrl('app_home'));
|
||||
}
|
||||
|
||||
public function logoutOPENID(Request $request)
|
||||
{
|
||||
$accesstoken = $request->getSession()->get('oauthAccesstoken');
|
||||
$idtoken = $request->getSession()->get('oauthIdtoken');
|
||||
$state = $request->getSession()->get('oauthState');
|
||||
|
||||
$this->tokenstorage->setToken(null);
|
||||
$request->getSession()->invalidate();
|
||||
|
||||
$url = $this->getParameter('oauthLogouturl');
|
||||
if ($url) {
|
||||
$callback = ($request->isSecure() ? 'https://' : 'http://').str_replace('//', '/', $this->getParameter('appWeburl').$this->getParameter('appAlias').$this->generateUrl('app_home'));
|
||||
$callback = substr($callback, 0, -1);
|
||||
|
||||
$url .= "?id_token_hint=$idtoken&scope=openid&post_logout_redirect_uri=$callback";
|
||||
|
||||
return $this->redirect($url);
|
||||
} else {
|
||||
return $this->redirect($this->generateUrl('app_home'));
|
||||
}
|
||||
}
|
||||
|
||||
// Génération automatique des niveau01 provenant de l'attribut casniveau01
|
||||
private function submitSSONiveau01($attributes, ManagerRegistry $em)
|
||||
{
|
||||
$attrNiveau01 = ('CAS' == $this->getParameter('appAuth') ? $this->getParameter('casNiveau01') : $this->getParameter('oauthNiveau01'));
|
||||
if (!$attrNiveau01) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Si l'utilisateur possège l'attribut niveau01 dans ses attributs
|
||||
if (array_key_exists($attrNiveau01, $attributes)) {
|
||||
if (!is_array($attributes[$attrNiveau01])) {
|
||||
$attributes[$attrNiveau01] = [$attributes[$attrNiveau01]];
|
||||
}
|
||||
|
||||
foreach ($attributes[$attrNiveau01] as $ssoniveau01) {
|
||||
$basedn = $this->getParameter('ldapBasedn');
|
||||
$name = $ssoniveau01;
|
||||
if ('' != $basedn) {
|
||||
// Si présence du basedn dans le nom du groupe = nous sommes en présence d'un DN = on récupere donc comme nom que son cn
|
||||
if (false !== stripos($name, $basedn)) {
|
||||
$tbname = explode(',', $name);
|
||||
$tbname = explode('=', $tbname[0]);
|
||||
$name = $tbname[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Recherche du groupe
|
||||
$niveau01 = $em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $name]);
|
||||
if (!$niveau01) {
|
||||
$niveau01 = new Niveau01();
|
||||
$niveau01->setLabel($name);
|
||||
$niveau01->setApikey(Uuid::uuid4());
|
||||
}
|
||||
|
||||
$niveau01->setAttributes('{"'.$attrNiveau01.'":"'.$ssoniveau01.'"}');
|
||||
$em->getManager()->persist($niveau01);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Génération automatique des groupes provenant de l'attribut casgroup ou oauthgroup
|
||||
private function submitSSOGroup($attributes, ManagerRegistry $em)
|
||||
{
|
||||
$attrGroup = ('CAS' == $this->getParameter('appAuth') ? $this->getParameter('casGroup') : $this->getParameter('oauthGroup'));
|
||||
if (!$attrGroup) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Si l'utilisateur possège l'attribut groupe dans ses attributs
|
||||
if (array_key_exists($attrGroup, $attributes)) {
|
||||
if (!is_array($attributes[$attrGroup])) {
|
||||
$attributes[$attrGroup] = [$attributes[$attrGroup]];
|
||||
}
|
||||
|
||||
foreach ($attributes[$attrGroup] as $ssogroup) {
|
||||
$basedn = $this->getParameter('ldapBasedn');
|
||||
$name = $ssogroup;
|
||||
if ('' != $basedn) {
|
||||
// Si présence du basedn dans le nom du groupe = nous sommes en présence d'un DN = on récupere donc comme nom que son cn
|
||||
if (false !== stripos($name, $basedn)) {
|
||||
$tbname = explode(',', $name);
|
||||
$tbname = explode('=', $tbname[0]);
|
||||
$name = $tbname[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Recherche du groupe
|
||||
$group = $em->getRepository("App\Entity\Group")->findOneBy(['label' => $name]);
|
||||
if (!$group) {
|
||||
$group = new Group();
|
||||
$group->setLabel($name);
|
||||
$group->setIsopen(false);
|
||||
$group->setIsworkgroup(false);
|
||||
$group->setApikey(Uuid::uuid4());
|
||||
}
|
||||
|
||||
$group->setAttributes('{"'.$attrGroup.'":"'.$ssogroup.'"}');
|
||||
$em->getManager()->persist($group);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function submituser($username, $firstname, $lastname, $email, $avatar, $niveau01, $em)
|
||||
{
|
||||
if (empty($email)) {
|
||||
$email = $username.'@nomail.com';
|
||||
}
|
||||
if (empty($avatar)) {
|
||||
$avatar = 'noavatar.png';
|
||||
}
|
||||
if (empty($firstname)) {
|
||||
$firstname = ' ';
|
||||
}
|
||||
if (empty($lastname)) {
|
||||
$lastname = $username;
|
||||
}
|
||||
$uuid = Uuid::uuid4();
|
||||
$password = $this->getParameter('appAuth').'PWD-'.$username.'-'.$uuid;
|
||||
|
||||
// Si aucun niveau01 on prend par défaut le niveau system
|
||||
if (!$niveau01) {
|
||||
$niveau01 = $em->getRepository('App\Entity\Niveau01')->find(-1);
|
||||
}
|
||||
|
||||
// Autogénération du user vu qu'il a pu se connecter
|
||||
$user = new User();
|
||||
|
||||
$user->setUsername($username);
|
||||
$user->setEmail($email);
|
||||
$user->setLastname($lastname);
|
||||
$user->setFirstname($firstname);
|
||||
$user->setApikey(Uuid::uuid4());
|
||||
|
||||
$user->setPassword($password);
|
||||
$user->setNiveau01($niveau01);
|
||||
|
||||
$user->setAvatar($avatar);
|
||||
$user->setIsvisible(true);
|
||||
$user->setRole('ROLE_USER');
|
||||
|
||||
if (in_array($username, $this->getParameter('appAdmins'))) {
|
||||
$user->setRole('ROLE_ADMIN');
|
||||
}
|
||||
|
||||
$em->getManager()->persist($user);
|
||||
$em->getManager()->flush();
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function updateuser($user, $firstname, $lastname, $email, $avatar, $em)
|
||||
{
|
||||
if ('noavatar.png' == $avatar) {
|
||||
$avatar = $user->getAvatar();
|
||||
}
|
||||
|
||||
if (!empty($lastname)) {
|
||||
$user->setLastname($lastname);
|
||||
}
|
||||
if (!empty($firstname)) {
|
||||
$user->setFirstname($firstname);
|
||||
}
|
||||
if (!empty($email)) {
|
||||
$user->setEmail($email);
|
||||
}
|
||||
if (!empty($avatar)) {
|
||||
$user->setAvatar($avatar);
|
||||
}
|
||||
|
||||
if (in_array($user->getUsername(), $this->getParameter('appAdmins'))) {
|
||||
$user->setRole('ROLE_ADMIN');
|
||||
}
|
||||
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
|
||||
private function autoconnexion($user, $redirect, Request $request)
|
||||
{
|
||||
// Récupérer le token de l'utilisateur
|
||||
$token = new UsernamePasswordToken($user, 'main', $user->getRoles());
|
||||
$this->tokenstorage->setToken($token);
|
||||
$request->getSession()->set('_security_main', serialize($token));
|
||||
|
||||
// Simuler l'evenement de connexion
|
||||
$event = new InteractiveLoginEvent($request, $token);
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->dispatch($event);
|
||||
|
||||
// Redirection
|
||||
if ($redirect) {
|
||||
return $this->redirect($redirect);
|
||||
} else {
|
||||
return $this->redirect($this->generateUrl('app_home'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class ThemeController extends AbstractController
|
||||
{
|
||||
@ -13,43 +14,43 @@ class ThemeController extends AbstractController
|
||||
{
|
||||
$finder = new Finder();
|
||||
|
||||
$dir = $this->getParameter('kernel.project_dir')."/public/themes";
|
||||
$url=$this->getParameter('appAlias')."themes";
|
||||
$dir = $this->getParameter('kernel.project_dir').'/public/themes';
|
||||
$url = $this->getParameter('appAlias').'themes';
|
||||
|
||||
$finder->in($dir)->directories()->depth('== 0');
|
||||
$themes=[];
|
||||
$themes[""]["dir"]="";
|
||||
$themes[""]["url"]=$url;
|
||||
$themes[""]["name"]="Thème par défaut";
|
||||
$themes = [];
|
||||
$themes['']['dir'] = '';
|
||||
$themes['']['url'] = $url;
|
||||
$themes['']['name'] = 'Thème par défaut';
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$key=$file->getRelativePathname();
|
||||
$themes[$key]["dir"]=$key;
|
||||
$themes[$key]["url"]=$url."/".$key;
|
||||
$key = $file->getRelativePathname();
|
||||
$themes[$key]['dir'] = $key;
|
||||
$themes[$key]['url'] = $url.'/'.$key;
|
||||
|
||||
$yml=Yaml::parseFile($dir.'/'.$key.'/info.yml');
|
||||
$themes[$key]["name"]=$yml["name"];
|
||||
$yml = Yaml::parseFile($dir.'/'.$key.'/info.yml');
|
||||
$themes[$key]['name'] = $yml['name'];
|
||||
}
|
||||
|
||||
$current=$request->getSession()->get("apptheme");
|
||||
$currentheme=$themes[$current];
|
||||
|
||||
$current = $request->getSession()->get('apptheme');
|
||||
$currentheme = $themes[$current];
|
||||
unset($themes[$current]);
|
||||
|
||||
return $this->render('Theme/list.html.twig',[
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
'currentheme' => $currentheme,
|
||||
'themes' => $themes
|
||||
return $this->render('Theme/list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usesidebar' => true,
|
||||
'currentheme' => $currentheme,
|
||||
'themes' => $themes,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function select($name,Request $request,ManagerRegistry $em)
|
||||
public function select($name, Request $request, ManagerRegistry $em)
|
||||
{
|
||||
$config=$em->getRepository("App\Entity\Config")->findoneBy(["id"=>"apptheme"]);
|
||||
$config = $em->getRepository("App\Entity\Config")->findoneBy(['id' => 'apptheme']);
|
||||
$config->setValue($name);
|
||||
|
||||
$em->getManager()->flush();
|
||||
$em->getManager()->flush();
|
||||
|
||||
return $this->redirectToRoute("app_admin_theme");
|
||||
return $this->redirectToRoute('app_admin_theme');
|
||||
}
|
||||
}
|
||||
|
@ -1,358 +1,359 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
use App\Entity\User as Entity;
|
||||
use App\Entity\UserGroup;
|
||||
use App\Entity\UserModo;
|
||||
use App\Form\UserType as Form;
|
||||
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
private $data="user";
|
||||
private $entity="App\Entity\User";
|
||||
private $twig="User/";
|
||||
private $route="app_admin_user";
|
||||
|
||||
public function list($access,Request $request): Response
|
||||
{
|
||||
if($access=="user"&&!$request->getSession()->get("showannuaire"))
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
private $data = 'user';
|
||||
private $entity = "App\Entity\User";
|
||||
private $twig = 'User/';
|
||||
private $route = 'app_admin_user';
|
||||
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>($access!="user"),
|
||||
"access"=>$access
|
||||
public function list($access, Request $request): Response
|
||||
{
|
||||
if ('user' == $access && !$request->getSession()->get('showannuaire')) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => ('user' != $access),
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function tablelist($access, Request $request,ManagerRegistry $em): Response
|
||||
{
|
||||
$query=$request->query->all();
|
||||
$start=$query['start'];
|
||||
$length=$query['length'];
|
||||
$search=$query['search'];
|
||||
$draw= $query['draw'];
|
||||
$ordercolumn=$query['order'][0]['column'];
|
||||
$orderdir=$query['order'][0]['dir'];
|
||||
$niveau01=null;
|
||||
$niveau02=null;
|
||||
public function tablelist($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$query = $request->query->all();
|
||||
$start = $query['start'];
|
||||
$length = $query['length'];
|
||||
$search = $query['search'];
|
||||
$draw = $query['draw'];
|
||||
$ordercolumn = $query['order'][0]['column'];
|
||||
$orderdir = $query['order'][0]['dir'];
|
||||
$niveau01 = null;
|
||||
$niveau02 = null;
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
switch($access) {
|
||||
case "admin":
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity,'entity')->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
|
||||
case "modo":
|
||||
case 'modo':
|
||||
$total = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from("App\Entity\UserModo",'usermodo')
|
||||
->where("usermodo.niveau01 = entity.niveau01")
|
||||
->andWhere("usermodo.user = :user")
|
||||
->setParameter("user", $this->getUser())
|
||||
->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
->from($this->entity, 'entity')
|
||||
->from("App\Entity\UserModo", 'usermodo')
|
||||
->where('usermodo.niveau01 = entity.niveau01')
|
||||
->andWhere('usermodo.user = :user')
|
||||
->setParameter('user', $this->getUser())
|
||||
->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
|
||||
default:
|
||||
$niveau01=$this->getUser()->getNiveau01();
|
||||
$niveau02=$this->getUser()->getNiveau02();
|
||||
$niveau01 = $this->getUser()->getNiveau01();
|
||||
$niveau02 = $this->getUser()->getNiveau02();
|
||||
|
||||
$qb=$em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity,'entity')->where('entity.isvisible=true');
|
||||
switch($request->getSession()->get("scopeannu")) {
|
||||
case "SAME_NIVEAU01":
|
||||
$qb->andWhere("entity.niveau01 = :niveau01")->setParameter("niveau01",$niveau01);
|
||||
break;
|
||||
$qb = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->where('entity.isvisible=true');
|
||||
switch ($request->getSession()->get('scopeannu')) {
|
||||
case 'SAME_NIVEAU01':
|
||||
$qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
|
||||
break;
|
||||
|
||||
case "SAME_NIVEAU02":
|
||||
$qb->andWhere("entity.niveau02 = :niveau02")->setParameter("niveau02",$niveau02);
|
||||
break;
|
||||
case 'SAME_NIVEAU02':
|
||||
$qb->andWhere('entity.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
|
||||
break;
|
||||
}
|
||||
|
||||
$total = $qb->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if(!$search||$search["value"]=="")
|
||||
if (!$search || '' == $search['value']) {
|
||||
$totalf = $total;
|
||||
else {
|
||||
switch($access) {
|
||||
case "admin":
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->from('App:Niveau01', 'niveau01')
|
||||
->where('entity.niveau01=niveau01.id')
|
||||
->andWhere('entity.username LIKE :value OR entity.firstname LIKE :value OR entity.lastname LIKE :value OR entity.email LIKE :value OR entity.roles LIKE :value OR niveau01.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
break;
|
||||
break;
|
||||
|
||||
case "modo":
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
case 'modo':
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->from('App:Niveau01', 'niveau01')
|
||||
->from("App:UserModo",'usermodo')
|
||||
->from('App:UserModo', 'usermodo')
|
||||
->where('entity.niveau01=niveau01.id')
|
||||
->andWhere('entity.username LIKE :value OR entity.firstname LIKE :value OR entity.lastname LIKE :value OR entity.email LIKE :value OR entity.roles LIKE :value OR niveau01.label LIKE :value')
|
||||
->andWhere("usermodo.niveau01 = entity.niveau01")
|
||||
->andWhere("usermodo.user = :userid")
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter("userid", $this->getUser()->getId())
|
||||
->andWhere('usermodo.niveau01 = entity.niveau01')
|
||||
->andWhere('usermodo.user = :userid')
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->setParameter('userid', $this->getUser()->getId())
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
break;
|
||||
|
||||
->getSingleScalarResult();
|
||||
break;
|
||||
|
||||
default:
|
||||
$qb = $em->getManager()->createQueryBuilder()
|
||||
$qb = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->from('App:Niveau01', 'niveau01')
|
||||
->where('entity.niveau01=niveau01.id')
|
||||
->andWhere('entity.isvisible=true')
|
||||
->andWhere('entity.username LIKE :value OR entity.firstname LIKE :value OR entity.lastname LIKE :value OR entity.email LIKE :value OR entity.roles LIKE :value OR niveau01.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
|
||||
switch($request->getSession()->get("scopeannu")) {
|
||||
case "SAME_NIVEAU01":
|
||||
$qb->andWhere("entity.niveau01 = :niveau01")->setParameter("niveau01",$niveau01);
|
||||
break;
|
||||
|
||||
case "SAME_NIVEAU02":
|
||||
$qb->andWhere("entity.niveau02 = :niveau02")->setParameter("niveau02",$niveau02);
|
||||
break;
|
||||
}
|
||||
|
||||
$totalf=$qb->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
switch ($request->getSession()->get('scopeannu')) {
|
||||
case 'SAME_NIVEAU01':
|
||||
$qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
|
||||
break;
|
||||
|
||||
case 'SAME_NIVEAU02':
|
||||
$qb->andWhere('entity.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
|
||||
break;
|
||||
}
|
||||
|
||||
$totalf = $qb->getQuery()->getSingleScalarResult();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
switch($access) {
|
||||
case "admin":
|
||||
$qb->select('entity')->from($this->entity,'entity')->from('App:Niveau01','niveau01');
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$qb->select('entity')->from($this->entity, 'entity')->from('App:Niveau01', 'niveau01');
|
||||
$qb->where('entity.niveau01=niveau01.id');
|
||||
break;
|
||||
|
||||
case "modo":
|
||||
$qb->select('entity')->from($this->entity,'entity')->from('App:Niveau01','niveau01')->from("App:UserModo",'usermodo');
|
||||
break;
|
||||
|
||||
case 'modo':
|
||||
$qb->select('entity')->from($this->entity, 'entity')->from('App:Niveau01', 'niveau01')->from('App:UserModo', 'usermodo');
|
||||
$qb->where('entity.niveau01=niveau01.id');
|
||||
$qb->andWhere("usermodo.niveau01 = entity.niveau01");
|
||||
$qb->andWhere("usermodo.user = :userid");
|
||||
$qb->setParameter("userid", $this->getUser()->getId());
|
||||
break;
|
||||
$qb->andWhere('usermodo.niveau01 = entity.niveau01');
|
||||
$qb->andWhere('usermodo.user = :userid');
|
||||
$qb->setParameter('userid', $this->getUser()->getId());
|
||||
break;
|
||||
|
||||
default:
|
||||
$qb->select('entity')->from($this->entity,'entity')->from('App:Niveau01','niveau01');
|
||||
$qb->select('entity')->from($this->entity, 'entity')->from('App:Niveau01', 'niveau01');
|
||||
$qb->where('entity.niveau01=niveau01.id');
|
||||
$qb->andWhere('entity.isvisible=true');
|
||||
|
||||
switch($request->getSession()->get("scopeannu")) {
|
||||
case "SAME_NIVEAU01":
|
||||
$qb->andWhere("entity.niveau01 = :niveau01")->setParameter("niveau01",$niveau01);
|
||||
break;
|
||||
switch ($request->getSession()->get('scopeannu')) {
|
||||
case 'SAME_NIVEAU01':
|
||||
$qb->andWhere('entity.niveau01 = :niveau01')->setParameter('niveau01', $niveau01);
|
||||
break;
|
||||
|
||||
case "SAME_NIVEAU02":
|
||||
$qb->andWhere("entity.niveau02 = :niveau02")->setParameter("niveau02",$niveau02);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if($search&&$search["value"]!="") {
|
||||
$qb ->andWhere('entity.username LIKE :value OR entity.firstname LIKE :value OR entity.lastname LIKE :value OR entity.email LIKE :value OR entity.roles LIKE :value OR niveau01.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
case 'SAME_NIVEAU02':
|
||||
$qb->andWhere('entity.niveau02 = :niveau02')->setParameter('niveau02', $niveau02);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if($ordercolumn) {
|
||||
if($access=="admin"||$access=="modo") {
|
||||
$ordercolumn=$ordercolumn-1;
|
||||
if ($search && '' != $search['value']) {
|
||||
$qb->andWhere('entity.username LIKE :value OR entity.firstname LIKE :value OR entity.lastname LIKE :value OR entity.email LIKE :value OR entity.roles LIKE :value OR niveau01.label LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
|
||||
if ($ordercolumn) {
|
||||
if ('admin' == $access || 'modo' == $access) {
|
||||
$ordercolumn = $ordercolumn - 1;
|
||||
}
|
||||
|
||||
switch($ordercolumn) {
|
||||
case 1 :
|
||||
$qb->orderBy('entity.username',$orderdir);
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
$qb->orderBy('entity.lastname',$orderdir);
|
||||
break;
|
||||
switch ($ordercolumn) {
|
||||
case 1:
|
||||
$qb->orderBy('entity.username', $orderdir);
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
$qb->orderBy('entity.firstname',$orderdir);
|
||||
break;
|
||||
case 2:
|
||||
$qb->orderBy('entity.lastname', $orderdir);
|
||||
break;
|
||||
|
||||
case 4 :
|
||||
$qb->orderBy('entity.email',$orderdir);
|
||||
break;
|
||||
case 3:
|
||||
$qb->orderBy('entity.firstname', $orderdir);
|
||||
break;
|
||||
|
||||
case 5 :
|
||||
$qb->orderBy('entity.telephonenumber',$orderdir);
|
||||
break;
|
||||
case 4:
|
||||
$qb->orderBy('entity.email', $orderdir);
|
||||
break;
|
||||
|
||||
case 6 :
|
||||
$qb->orderBy('niveau01.label',$orderdir);
|
||||
break;
|
||||
case 5:
|
||||
$qb->orderBy('entity.telephonenumber', $orderdir);
|
||||
break;
|
||||
|
||||
case 8 :
|
||||
$qb->orderBy('entity.visitedate',$orderdir);
|
||||
break;
|
||||
case 6:
|
||||
$qb->orderBy('niveau01.label', $orderdir);
|
||||
break;
|
||||
|
||||
case 9 :
|
||||
$qb->orderBy('entity.roles',$orderdir);
|
||||
break;
|
||||
case 8:
|
||||
$qb->orderBy('entity.visitedate', $orderdir);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$qb->orderBy('entity.roles', $orderdir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach($datas as $data) {
|
||||
foreach ($datas as $data) {
|
||||
// Action
|
||||
$action = "";
|
||||
switch($access) {
|
||||
case "admin":
|
||||
$action.="<a href='".$this->generateUrl($this->route.'_update', array('id'=>$data->getId()))."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
case "modo":
|
||||
$action.="<a href='".$this->generateUrl(str_replace("_admin_","_modo_",$this->route).'_update', array('id'=>$data->getId()))."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
$action = '';
|
||||
switch ($access) {
|
||||
case 'admin':
|
||||
$action .= "<a href='".$this->generateUrl($this->route.'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
case 'modo':
|
||||
$action .= "<a href='".$this->generateUrl(str_replace('_admin_', '_modo_', $this->route).'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
break;
|
||||
}
|
||||
|
||||
// Groupes
|
||||
$groups="";
|
||||
foreach($data->getGroups() as $usergroup) {
|
||||
$groups.=$usergroup->getGroup()->getLabel()."<br>";
|
||||
$groups = '';
|
||||
foreach ($data->getGroups() as $usergroup) {
|
||||
$groups .= $usergroup->getGroup()->getLabel().'<br>';
|
||||
}
|
||||
|
||||
// Roles
|
||||
$roles="";
|
||||
foreach($data->getRoles() as $role) {
|
||||
$roles.=$role."<br>";
|
||||
$roles = '';
|
||||
foreach ($data->getRoles() as $role) {
|
||||
$roles .= $role.'<br>';
|
||||
}
|
||||
|
||||
$tmp=array();
|
||||
if($access=="admin"||$access=="modo") array_push($tmp,$action);
|
||||
$tmp = [];
|
||||
if ('admin' == $access || 'modo' == $access) {
|
||||
array_push($tmp, $action);
|
||||
}
|
||||
|
||||
array_push($tmp,"<img src='".$this->generateUrl('app_minio_image',["file"=>"avatar/".$data->getAvatar()])."' class='avatar'>");
|
||||
array_push($tmp, "<img src='".$this->generateUrl('app_minio_image', ['file' => 'avatar/'.$data->getAvatar()])."' class='avatar'>");
|
||||
|
||||
array_push($tmp,$data->getUsername());
|
||||
array_push($tmp,$data->getLastname());
|
||||
array_push($tmp,$data->getFirstname());
|
||||
array_push($tmp,"<a href='mailto:".$data->getEmail()."'>".$data->getEmail()."</a>");
|
||||
array_push($tmp,$data->getTelephonenumber());
|
||||
array_push($tmp,$data->getNiveau01()->getLabel());
|
||||
array_push($tmp,($data->getNiveau02()?$data->getNiveau02()->getLabel():""));
|
||||
array_push($tmp,($data->getVisitedate()?$data->getVisitedate()->format("d/m/Y H:i")."<br>nb = ".$data->getVisitecpt():""));
|
||||
array_push($tmp,$roles);
|
||||
array_push($tmp,$groups);
|
||||
array_push($tmp, $data->getUsername());
|
||||
array_push($tmp, $data->getLastname());
|
||||
array_push($tmp, $data->getFirstname());
|
||||
array_push($tmp, "<a href='mailto:".$data->getEmail()."'>".$data->getEmail().'</a>');
|
||||
array_push($tmp, $data->getTelephonenumber());
|
||||
array_push($tmp, $data->getNiveau01()->getLabel());
|
||||
array_push($tmp, $data->getNiveau02() ? $data->getNiveau02()->getLabel() : '');
|
||||
array_push($tmp, $data->getVisitedate() ? $data->getVisitedate()->format('d/m/Y H:i').'<br>nb = '.$data->getVisitecpt() : '');
|
||||
array_push($tmp, $roles);
|
||||
array_push($tmp, $groups);
|
||||
|
||||
array_push($output["data"],$tmp);
|
||||
array_push($output['data'], $tmp);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
}
|
||||
|
||||
public function selectlist($access, Request $request,ManagerRegistry $em): Response
|
||||
public function selectlist($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$output=array();
|
||||
$page_limit=$request->query->get('page_limit');
|
||||
$q=$request->query->get('q');
|
||||
|
||||
$output = [];
|
||||
$page_limit = $request->query->get('page_limit');
|
||||
$q = $request->query->get('q');
|
||||
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('entity')->from($this->entity,'entity')
|
||||
$qb->select('entity')->from($this->entity, 'entity')
|
||||
->where('entity.username LIKE :value')
|
||||
->setParameter("value", "%".$q."%")
|
||||
->setParameter('value', '%'.$q.'%')
|
||||
->orderBy('entity.username');
|
||||
|
||||
$datas=$qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
|
||||
foreach($datas as $data) {
|
||||
array_push($output,array("id"=>$data->getId(),"text"=>$data->getUsername()));
|
||||
|
||||
$datas = $qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
|
||||
foreach ($datas as $data) {
|
||||
array_push($output, ['id' => $data->getId(), 'text' => $data->getUsername()]);
|
||||
}
|
||||
|
||||
$ret_string["results"]=$output;
|
||||
$response = new JsonResponse($ret_string);
|
||||
$ret_string['results'] = $output;
|
||||
$response = new JsonResponse($ret_string);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function submit($access, Request $request,ManagerRegistry $em): Response
|
||||
public function submit($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Vérifier que l'on puisse créer
|
||||
if($this->getParameter("appMasteridentity")!="SQL" && $this->getParameter("appSynchroPurgeUser"))
|
||||
if ('SQL' != $this->getParameter('appMasteridentity') && $this->getParameter('appSynchroPurgeUser')) {
|
||||
throw $this->createNotFoundException('Permission denied');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->cansubmit($access,$em);
|
||||
$this->cansubmit($access, $em);
|
||||
|
||||
// Initialisation de l'enregistrement
|
||||
$data = new Entity();
|
||||
$data->setAvatar("noavatar.png");
|
||||
$data->setAvatar('noavatar.png');
|
||||
$data->setIsvisible(true);
|
||||
$data->setApikey(Uuid::uuid4());
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"submit",
|
||||
"access"=>$access,
|
||||
"userid"=>$this->getUser()->getId(),
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"appNiveau01label"=>$this->GetParameter("appNiveau01label"),
|
||||
"appNiveau02label"=>$this->GetParameter("appNiveau02label"),
|
||||
));
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'submit',
|
||||
'access' => $access,
|
||||
'userid' => $this->getUser()->getId(),
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
||||
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// S'assurer que les modos ne donne pas des ROLE_ADMIN ou ROLE_USER au user qu'il submit
|
||||
if($access=="modo") {
|
||||
$roles=$data->getRoles();
|
||||
$roles=array_diff($roles,["ROLE_ADMIN","ROLE_MODO"]);
|
||||
if ('modo' == $access) {
|
||||
$roles = $data->getRoles();
|
||||
$roles = array_diff($roles, ['ROLE_ADMIN', 'ROLE_MODO']);
|
||||
$data->setRoles($roles);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// On récupère les groupes et on cacule ceux à ajouter ou à supprimer
|
||||
$lstgroups=array_filter(explode(",",$form->get("linkgroups")->getData()));
|
||||
$lstmodos=array_filter(explode(",",$form->get("linkmodos")->getData()));
|
||||
$lstgroups = array_filter(explode(',', $form->get('linkgroups')->getData()));
|
||||
$lstmodos = array_filter(explode(',', $form->get('linkmodos')->getData()));
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->persist($data);
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Ajout des groupes
|
||||
foreach($lstgroups as $idgroup) {
|
||||
$group=$em->getRepository("App\Entity\Group")->find($idgroup);
|
||||
$usergroup=$em->getRepository('App\Entity\UserGroup')->findBy(["user"=>$data,"group"=>$group]);
|
||||
if(!$usergroup) {
|
||||
$usergroup= new UserGroup();
|
||||
foreach ($lstgroups as $idgroup) {
|
||||
$group = $em->getRepository("App\Entity\Group")->find($idgroup);
|
||||
$usergroup = $em->getRepository('App\Entity\UserGroup')->findBy(['user' => $data, 'group' => $group]);
|
||||
if (!$usergroup) {
|
||||
$usergroup = new UserGroup();
|
||||
$usergroup->setUser($data);
|
||||
$usergroup->setGroup($group);
|
||||
$usergroup->setApikey(Uuid::uuid4());
|
||||
@ -364,11 +365,11 @@ class UserController extends AbstractController
|
||||
}
|
||||
|
||||
// Ajout des modos
|
||||
foreach($lstmodos as $idmodo) {
|
||||
$niveau01=$em->getRepository("App\Entity\Niveau01")->find($idmodo);
|
||||
$usermodo=$em->getRepository('App\Entity\UserModo')->findBy(["user"=>$data,"niveau01"=>$niveau01]);
|
||||
if(!$usermodo) {
|
||||
$usermodo= new UserModo();
|
||||
foreach ($lstmodos as $idmodo) {
|
||||
$niveau01 = $em->getRepository("App\Entity\Niveau01")->find($idmodo);
|
||||
$usermodo = $em->getRepository('App\Entity\UserModo')->findBy(['user' => $data, 'niveau01' => $niveau01]);
|
||||
if (!$usermodo) {
|
||||
$usermodo = new UserModo();
|
||||
$usermodo->setUser($data);
|
||||
$usermodo->setNiveau01($niveau01);
|
||||
|
||||
@ -378,100 +379,103 @@ class UserController extends AbstractController
|
||||
}
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"access"=>$access,
|
||||
"mode"=>"submit",
|
||||
"form"=>$form->createView(),
|
||||
$this->data=>$data,
|
||||
"listgroups"=>$this->getListGroups("admin",$em),
|
||||
"listmodos"=> $this->getListModos($em)
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'access' => $access,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
$this->data => $data,
|
||||
'listgroups' => $this->getListGroups('admin', $em),
|
||||
'listmodos' => $this->getListModos($em),
|
||||
]);
|
||||
}
|
||||
|
||||
public function profil($access,Request $request,ManagerRegistry $em): Response
|
||||
public function profil($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$id=$this->getUser()->getId();
|
||||
return $this->update($access,$id,$request,$em);
|
||||
$id = $this->getUser()->getId();
|
||||
|
||||
return $this->update($access, $id, $request, $em);
|
||||
}
|
||||
|
||||
public function update($access,$id,Request $request,ManagerRegistry $em): Response
|
||||
public function update($access, $id, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->canupdate($access,$data,$em);
|
||||
$this->canupdate($access, $data, $em);
|
||||
|
||||
// Récupération de l'ancien password
|
||||
$oldpassword=$data->getPassword();
|
||||
$oldpassword = $data->getPassword();
|
||||
|
||||
// Récuparation des groupes associés
|
||||
$oldlstgroups=[];
|
||||
foreach($data->getGroups() as $group){
|
||||
$oldlstgroups = [];
|
||||
foreach ($data->getGroups() as $group) {
|
||||
$oldlstgroups[] = $group->getGroup()->getId();
|
||||
}
|
||||
|
||||
// Récuparation des modos associés
|
||||
$oldlstmodos=[];
|
||||
foreach($data->getModos() as $modo){
|
||||
$oldlstmodos = [];
|
||||
foreach ($data->getModos() as $modo) {
|
||||
$oldlstmodos[] = $modo->getNiveau01()->getId();
|
||||
}
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array(
|
||||
"mode"=>"update",
|
||||
"access"=>$access,
|
||||
"userid"=>$this->getUser()->getId(),
|
||||
"appMasteridentity"=>$this->GetParameter("appMasteridentity"),
|
||||
"appNiveau01label"=>$this->GetParameter("appNiveau01label"),
|
||||
"appNiveau02label"=>$this->GetParameter("appNiveau02label"),
|
||||
));
|
||||
|
||||
$form = $this->createForm(Form::class, $data, [
|
||||
'mode' => 'update',
|
||||
'access' => $access,
|
||||
'userid' => $this->getUser()->getId(),
|
||||
'appMasteridentity' => $this->GetParameter('appMasteridentity'),
|
||||
'appNiveau01label' => $this->GetParameter('appNiveau01label'),
|
||||
'appNiveau02label' => $this->GetParameter('appNiveau02label'),
|
||||
]);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// S'assurer que les modos ne donne pas des ROLE_ADMIN ou ROLE_USER au user qu'il update
|
||||
if($access=="modo") {
|
||||
$roles=$data->getRoles();
|
||||
$roles=array_diff($roles,["ROLE_ADMIN","ROLE_MODO"]);
|
||||
if ('modo' == $access) {
|
||||
$roles = $data->getRoles();
|
||||
$roles = array_diff($roles, ['ROLE_ADMIN', 'ROLE_MODO']);
|
||||
$data->setRoles($roles);
|
||||
}
|
||||
|
||||
// Si pas de changement de password on replace l'ancien
|
||||
if($data->getPassword()=="") {
|
||||
$data->setPassword($oldpassword);
|
||||
if ('' == $data->getPassword()) {
|
||||
$data->setPassword($oldpassword);
|
||||
}
|
||||
// Sinon on encode le nouveau
|
||||
else {
|
||||
$data->setPassword($data->getPassword());
|
||||
}
|
||||
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->flush();
|
||||
|
||||
|
||||
// On récupère les groupes et on cacule ceux à ajouter ou à supprimer
|
||||
$lstgroups=array_filter(explode(",",$form->get("linkgroups")->getData()));
|
||||
$removegroups=array_diff($oldlstgroups,$lstgroups);
|
||||
$addgroups=array_diff($lstgroups,$oldlstgroups);
|
||||
|
||||
$lstgroups = array_filter(explode(',', $form->get('linkgroups')->getData()));
|
||||
$removegroups = array_diff($oldlstgroups, $lstgroups);
|
||||
$addgroups = array_diff($lstgroups, $oldlstgroups);
|
||||
|
||||
// Ajout des nouveaux groupes
|
||||
foreach($addgroups as $idgroup) {
|
||||
$group=$em->getRepository("App\Entity\Group")->find($idgroup);
|
||||
$usergroup=$em->getRepository('App\Entity\UserGroup')->findOneBy(["user"=>$data,"group"=>$group]);
|
||||
if(!$usergroup) {
|
||||
$usergroup= new UserGroup();
|
||||
foreach ($addgroups as $idgroup) {
|
||||
$group = $em->getRepository("App\Entity\Group")->find($idgroup);
|
||||
$usergroup = $em->getRepository('App\Entity\UserGroup')->findOneBy(['user' => $data, 'group' => $group]);
|
||||
if (!$usergroup) {
|
||||
$usergroup = new UserGroup();
|
||||
$usergroup->setUser($data);
|
||||
$usergroup->setGroup($group);
|
||||
$usergroup->setApikey(Uuid::uuid4());
|
||||
@ -482,27 +486,26 @@ class UserController extends AbstractController
|
||||
}
|
||||
|
||||
// Suppression des groupes obsolètes
|
||||
foreach($removegroups as $idgroup) {
|
||||
$group=$em->getRepository("App\Entity\Group")->find($idgroup);
|
||||
$usergroup=$em->getRepository('App\Entity\UserGroup')->findOneBy(["user"=>$data,"group"=>$group]);
|
||||
if($usergroup) {
|
||||
foreach ($removegroups as $idgroup) {
|
||||
$group = $em->getRepository("App\Entity\Group")->find($idgroup);
|
||||
$usergroup = $em->getRepository('App\Entity\UserGroup')->findOneBy(['user' => $data, 'group' => $group]);
|
||||
if ($usergroup) {
|
||||
$em->getManager()->remove($usergroup);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
// On récupère les modos et on cacule ceux à ajouter ou à supprimer
|
||||
$linkmodos=array_filter(explode(",",$form->get("linkmodos")->getData()));
|
||||
$removemodos=array_diff($oldlstmodos,$linkmodos);
|
||||
$addmodos=array_diff($linkmodos,$oldlstmodos);
|
||||
|
||||
$linkmodos = array_filter(explode(',', $form->get('linkmodos')->getData()));
|
||||
$removemodos = array_diff($oldlstmodos, $linkmodos);
|
||||
$addmodos = array_diff($linkmodos, $oldlstmodos);
|
||||
|
||||
// Ajout des nouveaux modos
|
||||
foreach($addmodos as $idmodo) {
|
||||
$niveau01=$em->getRepository("App\Entity\Niveau01")->find($idmodo);
|
||||
$usermodo=$em->getRepository('App\Entity\UserModo')->findOneBy(["user"=>$data,"niveau01"=>$niveau01]);
|
||||
if(!$usermodo) {
|
||||
$usermodo= new UserModo();
|
||||
foreach ($addmodos as $idmodo) {
|
||||
$niveau01 = $em->getRepository("App\Entity\Niveau01")->find($idmodo);
|
||||
$usermodo = $em->getRepository('App\Entity\UserModo')->findOneBy(['user' => $data, 'niveau01' => $niveau01]);
|
||||
if (!$usermodo) {
|
||||
$usermodo = new UserModo();
|
||||
$usermodo->setUser($data);
|
||||
$usermodo->setNiveau01($niveau01);
|
||||
$em->getManager()->persist($usermodo);
|
||||
@ -511,158 +514,184 @@ class UserController extends AbstractController
|
||||
}
|
||||
|
||||
// Suppression des modos obsolètes
|
||||
foreach($removemodos as $idmodo) {
|
||||
$niveau01=$em->getRepository("App\Entity\Niveau01")->find($idmodo);
|
||||
$usermodo=$em->getRepository('App\Entity\UserModo')->findOneBy(["user"=>$data,"niveau01"=>$niveau01]);
|
||||
if($usermodo) {
|
||||
foreach ($removemodos as $idmodo) {
|
||||
$niveau01 = $em->getRepository("App\Entity\Niveau01")->find($idmodo);
|
||||
$usermodo = $em->getRepository('App\Entity\UserModo')->findOneBy(['user' => $data, 'niveau01' => $niveau01]);
|
||||
if ($usermodo) {
|
||||
$em->getManager()->remove($usermodo);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
// Retour à la liste
|
||||
if($access=="user")
|
||||
return $this->redirectToRoute("app_home");
|
||||
else
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
if ('user' == $access) {
|
||||
return $this->redirectToRoute('app_home');
|
||||
} else {
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>($access=="admin"),
|
||||
"access"=>$access,
|
||||
"mode"=>"update",
|
||||
"form"=>$form->createView(),
|
||||
$this->data=>$data,
|
||||
"listgroups"=>$this->getListGroups($access,$em),
|
||||
"listmodos"=> $this->getListModos($em),
|
||||
"maxsize"=>($access=="user"?1200:null),
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => ('admin' == $access),
|
||||
'access' => $access,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
$this->data => $data,
|
||||
'listgroups' => $this->getListGroups($access, $em),
|
||||
'listmodos' => $this->getListModos($em),
|
||||
'maxsize' => ('user' == $access ? 1200 : null),
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($access,$id,Request $request,ManagerRegistry $em): Response
|
||||
public function delete($access, $id, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Controler les permissions
|
||||
$this->candelete($access,$data,$em);
|
||||
$this->candelete($access, $data, $em);
|
||||
|
||||
// Tentative de suppression
|
||||
try{
|
||||
try {
|
||||
$em->getManager()->remove($data);
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add("error", $e->getMessage());
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route)."_update",["id"=>$id]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(str_replace("_admin_","_".$access."_",$this->route));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
|
||||
|
||||
protected function getListGroups($access,$em)
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route).'_update', ['id' => $id]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(str_replace('_admin_', '_'.$access.'_', $this->route));
|
||||
}
|
||||
|
||||
protected function getListGroups($access, $em)
|
||||
{
|
||||
$qb=$em->getManager()->createQueryBuilder();
|
||||
$qb->select('b')->from('App:Group','b');
|
||||
if($access!="admin") $qb->where("b.isopen=true AND b.isworkgroup=true");
|
||||
$qb->andWhere("b.ldapfilter IS NULL");
|
||||
$qb->andWhere("b.attributes IS NULL");
|
||||
$qb->andWhere("b.id>0");
|
||||
$datas=$qb->getQuery()->getResult();
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('b')->from('App:Group', 'b');
|
||||
if ('admin' != $access) {
|
||||
$qb->where('b.isopen=true AND b.isworkgroup=true');
|
||||
}
|
||||
$qb->andWhere('b.ldapfilter IS NULL');
|
||||
$qb->andWhere('b.attributes IS NULL');
|
||||
$qb->andWhere('b.id>0');
|
||||
$datas = $qb->getQuery()->getResult();
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getListModos($em)
|
||||
{
|
||||
$qb=$em->getManager()->createQueryBuilder();
|
||||
$qb->select('b')->from('App:Niveau01','b');
|
||||
$datas=$qb->getQuery()->getResult();
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('b')->from('App:Niveau01', 'b');
|
||||
$datas = $qb->getQuery()->getResult();
|
||||
|
||||
return $datas;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function cansubmit($access,$em) {
|
||||
switch($access) {
|
||||
case "admin" : return true; break;
|
||||
case "modo" : return true; break;
|
||||
private function cansubmit($access, $em)
|
||||
{
|
||||
switch ($access) {
|
||||
case 'admin': return true;
|
||||
break;
|
||||
case 'modo': return true;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
|
||||
private function canupdate($access,$entity,$em) {
|
||||
switch($access) {
|
||||
case "admin" : return true; break;
|
||||
case "modo" :
|
||||
$usermodo=$em->getRepository("App\Entity\UserModo")->findOneBy(["user"=>$this->getUser(),"niveau01"=>$entity->getNiveau01()]);
|
||||
if(!$usermodo) throw $this->createAccessDeniedException('Permission denied');
|
||||
return true;
|
||||
break;
|
||||
case "user" :
|
||||
if($this->getUser()->getId()!=$entity->getId()) throw $this->createAccessDeniedException('Permission denied');
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
private function candelete($access,$entity,$em) {
|
||||
switch($access) {
|
||||
case "admin" : return true; break;
|
||||
case "modo" :
|
||||
$usermodo=$em->getRepository("App\Entity\UserModo")->findOneBy(["user"=>$this->getUser(),"niveau01"=>$entity->getNiveau01()]);
|
||||
if(!$usermodo) throw $this->createAccessDeniedException('Permission denied');
|
||||
|
||||
if($entity->hasRole("ROLE_ADMIN")||$entity->hasRole("ROLE_MODO")) throw $this->createAccessDeniedException('Permission denied');
|
||||
return true;
|
||||
break;
|
||||
case "user" :
|
||||
if($this->getUser()->getId()!=$entity->getId()) throw $this->createAccessDeniedException('Permission denied');
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
public function preference($access,Request $request,ManagerRegistry $em): Response
|
||||
private function canupdate($access, $entity, $em)
|
||||
{
|
||||
$key=$request->request->get('key');
|
||||
$id=$request->request->get('id');
|
||||
$value=$request->request->get('value');
|
||||
|
||||
switch ($access) {
|
||||
case 'admin': return true;
|
||||
break;
|
||||
case 'modo':
|
||||
$usermodo = $em->getRepository("App\Entity\UserModo")->findOneBy(['user' => $this->getUser(), 'niveau01' => $entity->getNiveau01()]);
|
||||
if (!$usermodo) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
case 'user':
|
||||
if ($this->getUser()->getId() != $entity->getId()) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
private function candelete($access, $entity, $em)
|
||||
{
|
||||
switch ($access) {
|
||||
case 'admin': return true;
|
||||
break;
|
||||
case 'modo':
|
||||
$usermodo = $em->getRepository("App\Entity\UserModo")->findOneBy(['user' => $this->getUser(), 'niveau01' => $entity->getNiveau01()]);
|
||||
if (!$usermodo) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
if ($entity->hasRole('ROLE_ADMIN') || $entity->hasRole('ROLE_MODO')) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
case 'user':
|
||||
if ($this->getUser()->getId() != $entity->getId()) {
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
throw $this->createAccessDeniedException('Permission denied');
|
||||
}
|
||||
|
||||
public function preference($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$key = $request->request->get('key');
|
||||
$id = $request->request->get('id');
|
||||
$value = $request->request->get('value');
|
||||
|
||||
// Récupérer les préférences de l'utilisateur
|
||||
$preference=$this->getUser()->getPreference();
|
||||
$preference = $this->getUser()->getPreference();
|
||||
|
||||
// Mise à jour de la préférence
|
||||
$toupdate=false;
|
||||
if(!is_array($preference)) {
|
||||
$toupdate=true;
|
||||
$preference=[];
|
||||
$toupdate = false;
|
||||
if (!is_array($preference)) {
|
||||
$toupdate = true;
|
||||
$preference = [];
|
||||
}
|
||||
|
||||
if(!array_key_exists($key,$preference)) {
|
||||
$toupdate=true;
|
||||
$preference[$key]=[];
|
||||
if (!array_key_exists($key, $preference)) {
|
||||
$toupdate = true;
|
||||
$preference[$key] = [];
|
||||
}
|
||||
if((!array_key_exists($id,$preference[$key]))) {
|
||||
$toupdate=true;
|
||||
$preference[$key][$id]=$value;
|
||||
if (!array_key_exists($id, $preference[$key])) {
|
||||
$toupdate = true;
|
||||
$preference[$key][$id] = $value;
|
||||
}
|
||||
if ($preference[$key][$id] != $value) {
|
||||
$toupdate = true;
|
||||
$preference[$key][$id] = $value;
|
||||
}
|
||||
if($preference[$key][$id]!=$value) {
|
||||
$toupdate=true;
|
||||
$preference[$key][$id]=$value;
|
||||
}
|
||||
|
||||
// Mise à jour des préferences
|
||||
if($toupdate) {
|
||||
if ($toupdate) {
|
||||
$this->getUser()->setPreference($preference);
|
||||
$em->getManager()->flush();
|
||||
$em->getManager()->flush();
|
||||
}
|
||||
|
||||
|
||||
return new Response();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,118 +2,121 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use App\Entity\Whitelist as Entity;
|
||||
use App\Form\WhitelistType as Form;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class WhitelistController extends AbstractController
|
||||
{
|
||||
private $data="whitelist";
|
||||
private $entity="App\Entity\Whitelist";
|
||||
private $twig="Whitelist/";
|
||||
private $route="app_admin_whitelist";
|
||||
private $data = 'whitelist';
|
||||
private $entity = "App\Entity\Whitelist";
|
||||
private $twig = 'Whitelist/';
|
||||
private $route = 'app_admin_whitelist';
|
||||
|
||||
public function list($access): Response
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig',[
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"access"=>$access,
|
||||
{
|
||||
return $this->render($this->twig.'list.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function tablelist(Request $request,ManagerRegistry $em): Response
|
||||
{
|
||||
$query=$request->query->all();
|
||||
$start=$query['start'];
|
||||
$length=$query['length'];
|
||||
$search=$query['search'];
|
||||
$draw= $query['draw'];
|
||||
$ordercolumn=$query['order'][0]['column'];
|
||||
$orderdir=$query['order'][0]['dir'];
|
||||
public function tablelist(Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
$query = $request->query->all();
|
||||
$start = $query['start'];
|
||||
$length = $query['length'];
|
||||
$search = $query['search'];
|
||||
$draw = $query['draw'];
|
||||
$ordercolumn = $query['order'][0]['column'];
|
||||
$orderdir = $query['order'][0]['dir'];
|
||||
|
||||
// Nombre total d'enregistrement
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity,'entity')->getQuery()->getSingleScalarResult();
|
||||
$total = $em->getManager()->createQueryBuilder()->select('COUNT(entity)')->from($this->entity, 'entity')->getQuery()->getSingleScalarResult();
|
||||
|
||||
// Nombre d'enregistrement filtré
|
||||
if(!$search||$search["value"]=="")
|
||||
if (!$search || '' == $search['value']) {
|
||||
$totalf = $total;
|
||||
else {
|
||||
$totalf= $em->getManager()->createQueryBuilder()
|
||||
} else {
|
||||
$totalf = $em->getManager()->createQueryBuilder()
|
||||
->select('COUNT(entity)')
|
||||
->from($this->entity,'entity')
|
||||
->from($this->entity, 'entity')
|
||||
->where('entity.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%")
|
||||
->setParameter('value', '%'.$search['value'].'%')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
// Construction du tableau de retour
|
||||
$output = array(
|
||||
$output = [
|
||||
'draw' => $draw,
|
||||
'recordsFiltered' => $totalf,
|
||||
'recordsTotal' => $total,
|
||||
'data' => array(),
|
||||
);
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
// Parcours des Enregistrement
|
||||
$qb = $em->getManager()->createQueryBuilder();
|
||||
$qb->select('entity')->from($this->entity,'entity');
|
||||
if($search&&$search["value"]!="") {
|
||||
$qb ->andWhere('entity.label LIKE :value')
|
||||
->setParameter("value", "%".$search["value"]."%");
|
||||
$qb->select('entity')->from($this->entity, 'entity');
|
||||
if ($search && '' != $search['value']) {
|
||||
$qb->andWhere('entity.label LIKE :value')
|
||||
->setParameter('value', '%'.$search['value'].'%');
|
||||
}
|
||||
|
||||
if($ordercolumn) {
|
||||
switch($ordercolumn) {
|
||||
case 1 :
|
||||
$qb->orderBy('entity.label',$orderdir);
|
||||
break;
|
||||
if ($ordercolumn) {
|
||||
switch ($ordercolumn) {
|
||||
case 1:
|
||||
$qb->orderBy('entity.label', $orderdir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$datas=$qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
$datas = $qb->setFirstResult($start)->setMaxResults($length)->getQuery()->getResult();
|
||||
|
||||
foreach($datas as $data) {
|
||||
foreach ($datas as $data) {
|
||||
// Action
|
||||
$action = "";
|
||||
$action.="<a href='".$this->generateUrl($this->route.'_update', array('id'=>$data->getId()))."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
$action = '';
|
||||
$action .= "<a href='".$this->generateUrl($this->route.'_update', ['id' => $data->getId()])."'><i class='fa fa-file fa-fw fa-2x'></i></a>";
|
||||
|
||||
$tmp=array();
|
||||
array_push($tmp,$action);
|
||||
array_push($tmp,$data->getLabel());
|
||||
$tmp = [];
|
||||
array_push($tmp, $action);
|
||||
array_push($tmp, $data->getLabel());
|
||||
|
||||
if($this->getParameter("appMasteridentity")=="LDAP"||$this->getParameter("appSynchro")=="LDAP2NINE") array_push($tmp,$data->getLdapfilter());
|
||||
if($this->getParameter("appMasteridentity")=="SSO") array_push($tmp,$data->getAttributes());
|
||||
if ('LDAP' == $this->getParameter('appMasteridentity') || 'LDAP2NINE' == $this->getParameter('appSynchro')) {
|
||||
array_push($tmp, $data->getLdapfilter());
|
||||
}
|
||||
if ('SSO' == $this->getParameter('appMasteridentity')) {
|
||||
array_push($tmp, $data->getAttributes());
|
||||
}
|
||||
|
||||
array_push($output["data"],$tmp);
|
||||
array_push($output['data'], $tmp);
|
||||
}
|
||||
|
||||
// Retour
|
||||
return new JsonResponse($output);
|
||||
}
|
||||
}
|
||||
|
||||
public function submit($access,Request $request,ManagerRegistry $em): Response
|
||||
public function submit($access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data = new Entity();
|
||||
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"submit"));
|
||||
$form = $this->createForm(Form::class, $data, ['mode' => 'submit']);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
// Sauvegarde
|
||||
$em->getManager()->persist($data);
|
||||
$em->getManager()->flush();
|
||||
@ -121,82 +124,87 @@ class WhitelistController extends AbstractController
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
"useheader"=>true,
|
||||
"usemenu"=>false,
|
||||
"usesidebar"=>true,
|
||||
"mode"=>"submit",
|
||||
"form"=>$form->createView(),
|
||||
$this->data=>$data,
|
||||
"access"=>$access,
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
'mode' => 'submit',
|
||||
'form' => $form->createView(),
|
||||
$this->data => $data,
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function update($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Initialisation de l'enregistrement
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Création du formulaire
|
||||
$form = $this->createForm(Form::class,$data,array("mode"=>"update"));
|
||||
$form = $this->createForm(Form::class, $data, ['mode' => 'update']);
|
||||
|
||||
// Récupération des data du formulaire
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Sur validation
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
if ($form->get('submit')->isClicked() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$em->getManager()->flush();
|
||||
|
||||
// Retour à la liste
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
|
||||
// Affichage du formulaire
|
||||
return $this->render($this->twig.'edit.html.twig', [
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
"access"=>$access,
|
||||
'useheader' => true,
|
||||
'usemenu' => false,
|
||||
'usesidebar' => true,
|
||||
$this->data => $data,
|
||||
'mode' => 'update',
|
||||
'form' => $form->createView(),
|
||||
'access' => $access,
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete($id,$access,Request $request,ManagerRegistry $em): Response
|
||||
public function delete($id, $access, Request $request, ManagerRegistry $em): Response
|
||||
{
|
||||
// Récupération de l'enregistrement courant
|
||||
$data=$em->getRepository($this->entity)->find($id);
|
||||
if (!$data) throw $this->createNotFoundException('Unable to find entity.');
|
||||
$data = $em->getRepository($this->entity)->find($id);
|
||||
if (!$data) {
|
||||
throw $this->createNotFoundException('Unable to find entity.');
|
||||
}
|
||||
|
||||
// Tentative de suppression
|
||||
try{
|
||||
try {
|
||||
$em->getManager()->remove($data);
|
||||
$em->getManager()->flush();
|
||||
} catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add('error', $e->getMessage());
|
||||
|
||||
return $this->redirectToRoute($this->route.'_update', ['id' => $id]);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$request->getSession()->getFlashBag()->add("error", $e->getMessage());
|
||||
return $this->redirectToRoute($this->route."_update",["id"=>$id]);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute($this->route);
|
||||
|
||||
return $this->redirectToRoute($this->route);
|
||||
}
|
||||
|
||||
public function is(Request $request,ManagerRegistry $em)
|
||||
public function is(Request $request, ManagerRegistry $em)
|
||||
{
|
||||
$email=$request->request->get('email');
|
||||
$email=explode("@",$email);
|
||||
$domaine=end($email);
|
||||
$email = $request->request->get('email');
|
||||
$email = explode('@', $email);
|
||||
$domaine = end($email);
|
||||
|
||||
// Rechercher le mail dans la liste blanche
|
||||
$whitelist=$em->getRepository($this->entity)->findOneBy(["label"=>$domaine]);
|
||||
if($whitelist)
|
||||
return new Response("OK", 200);
|
||||
else
|
||||
return new Response("KO", 200);
|
||||
}
|
||||
$whitelist = $em->getRepository($this->entity)->findOneBy(['label' => $domaine]);
|
||||
if ($whitelist) {
|
||||
return new Response('OK', 200);
|
||||
} else {
|
||||
return new Response('KO', 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user