fix(fixtureavatar): fixcture auto avatar & timesession & font & menu & redirect #5
|
@ -8,18 +8,18 @@ use App\Entity\Niveau03;
|
||||||
use App\Entity\Niveau04;
|
use App\Entity\Niveau04;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Entity\UserModo;
|
use App\Entity\UserModo;
|
||||||
|
use App\Service\MinioService;
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\ORM\Id\AssignedGenerator;
|
use Doctrine\ORM\Id\AssignedGenerator;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
|
||||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
|
||||||
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
|
|
||||||
use App\Service\MinioService;
|
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
|
|
||||||
class AppFixtures extends Fixture
|
class AppFixtures extends Fixture
|
||||||
{
|
{
|
||||||
|
@ -53,8 +53,8 @@ class AppFixtures extends Fixture
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
$this->colorbg=$manager->getRepository("App\Entity\Config")->find("colorbgbodydark")->getValue();
|
$this->colorbg = $manager->getRepository("App\Entity\Config")->find('colorbgbodydark')->getValue();
|
||||||
$this->colorft=$manager->getRepository("App\Entity\Config")->find("colorfttitledark")->getValue();
|
$this->colorft = $manager->getRepository("App\Entity\Config")->find('colorfttitledark')->getValue();
|
||||||
|
|
||||||
// app:Synchro
|
// app:Synchro
|
||||||
$manager->clear();
|
$manager->clear();
|
||||||
|
@ -250,7 +250,6 @@ class AppFixtures extends Fixture
|
||||||
$user->setNiveau01($niveau02->getNiveau01());
|
$user->setNiveau01($niveau02->getNiveau01());
|
||||||
$user->setNiveau02($niveau02);
|
$user->setNiveau02($niveau02);
|
||||||
|
|
||||||
|
|
||||||
$this->generateavatar($username);
|
$this->generateavatar($username);
|
||||||
$user->setAvatar($username.'.png');
|
$user->setAvatar($username.'.png');
|
||||||
|
|
||||||
|
@ -290,7 +289,6 @@ class AppFixtures extends Fixture
|
||||||
$this->generateavatar($username);
|
$this->generateavatar($username);
|
||||||
$user->setAvatar($username.'.png');
|
$user->setAvatar($username.'.png');
|
||||||
|
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,10 +362,11 @@ class AppFixtures extends Fixture
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateavatar($username) {
|
private function generateavatar($username)
|
||||||
|
{
|
||||||
$avatar = new InitialAvatar();
|
$avatar = new InitialAvatar();
|
||||||
$image = $avatar->name($username)->height(100)->width(100)->background($this->colorbg)->color($this->colorft)->generate();
|
$image = $avatar->name($username)->height(100)->width(100)->background($this->colorbg)->color($this->colorft)->generate();
|
||||||
file_put_contents($this->kernel->getProjectDir().'/var/tmp/avatar/'.$username.'.png',$image->stream('png', 90));
|
file_put_contents($this->kernel->getProjectDir().'/var/tmp/avatar/'.$username.'.png', $image->stream('png', 90));
|
||||||
$this->minio->upload($this->kernel->getProjectDir().'/var/tmp/avatar/'.$username.'.png', 'avatar/'.$username.'.png', true);
|
$this->minio->upload($this->kernel->getProjectDir().'/var/tmp/avatar/'.$username.'.png', 'avatar/'.$username.'.png', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\EventListener;
|
namespace App\EventListener;
|
||||||
|
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
|
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
|
||||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||||
|
|
||||||
class ExceptionListener implements EventSubscriberInterface
|
class ExceptionListener implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
private $router;
|
private $router;
|
||||||
|
|
||||||
public function __construct(UrlGeneratorInterface $router) {
|
public function __construct(UrlGeneratorInterface $router)
|
||||||
$this->router=$router;
|
{
|
||||||
|
$this->router = $router;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSubscribedEvents(): array
|
public static function getSubscribedEvents(): array
|
||||||
|
@ -32,7 +33,7 @@ class ExceptionListener implements EventSubscriberInterface
|
||||||
public function onKernelException(ExceptionEvent $event): void
|
public function onKernelException(ExceptionEvent $event): void
|
||||||
{
|
{
|
||||||
$exception = $event->getThrowable();
|
$exception = $event->getThrowable();
|
||||||
if (!$exception instanceof AccessDeniedException&&!$exception instanceof NotFoundHttpException) {
|
if (!$exception instanceof AccessDeniedException && !$exception instanceof NotFoundHttpException) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +41,5 @@ class ExceptionListener implements EventSubscriberInterface
|
||||||
|
|
||||||
// optionally set the custom response
|
// optionally set the custom response
|
||||||
$event->setResponse($response);
|
$event->setResponse($response);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -157,6 +157,8 @@ class LdapService
|
||||||
break;
|
break;
|
||||||
case 'basedn': return $this->basedn;
|
case 'basedn': return $this->basedn;
|
||||||
break;
|
break;
|
||||||
|
case 'baseorganisation': return $this->baseorganisation;
|
||||||
|
break;
|
||||||
case 'filteruser': return $this->filteruser;
|
case 'filteruser': return $this->filteruser;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -187,13 +189,27 @@ class LdapService
|
||||||
return $this->resultToArray($result);
|
return $this->resultToArray($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteByDN($dn)
|
public function deleteByDN($dn, $recursive = false)
|
||||||
{
|
{
|
||||||
$connection = $this->connect();
|
$connection = $this->connect();
|
||||||
|
if (false == $recursive) {
|
||||||
$removed = ldap_delete($connection, $dn);
|
$removed = ldap_delete($connection, $dn);
|
||||||
if (!$removed) {
|
if (!$removed) {
|
||||||
$this->ldapError();
|
$this->ldapError();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// searching for sub entries
|
||||||
|
$sr = ldap_list($connection, $dn, 'ObjectClass=*', ['']);
|
||||||
|
$info = ldap_get_entries($connection, $sr);
|
||||||
|
for ($i = 0; $i < $info['count']; ++$i) {
|
||||||
|
$result = $this->deleteByDN($info[$i]['dn'], $recursive);
|
||||||
|
if (!$result) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ldap_delete($connection, $dn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rename($oldDN, $newDN, $parentDN = '', $deleteOldDN = true)
|
public function rename($oldDN, $newDN, $parentDN = '', $deleteOldDN = true)
|
||||||
|
|
Loading…
Reference in New Issue