src/Controller/DefaultController.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Security\Users;
  4. use App\Services\MailService;
  5. use App\Services\SerializationService;
  6. use App\Services\TestService;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  11. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  12. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  13. use Symfony\Component\Security\Core\Security;
  14. class DefaultController extends AbstractController
  15. {
  16.     private $em;
  17.     private $serialization;
  18.     private $passwordHasher;
  19.     private $tokenStorage;
  20.     private $testService;
  21.     private $serializationService;
  22.     private $mailService;
  23.     public function __construct(
  24.         EntityManagerInterface $entityManager,
  25.         UserPasswordHasherInterface $passwordHasher,
  26.         Security $security,
  27.         TestService $testService,
  28.         SerializationService $serializationService,
  29.         MailService $mailService,
  30.         TokenStorageInterface $tokenStorage)
  31.     {
  32.         $this->em $entityManager;
  33.         $this->passwordHasher $passwordHasher;
  34.         $this->tokenStorage $tokenStorage;
  35.         $this->testService $testService;
  36.         $this->serializationService $serializationService;
  37.         $this->mailService $mailService;
  38.     }
  39.     /**
  40.      * @Route("/", name="index")
  41.      */
  42.     public function index()
  43.     {
  44.         return $this->render("index.html.twig");
  45.     }
  46.     /**
  47.      * @Route("/auth_test", name="auth_test")
  48.      */
  49.     public function auth_test()
  50.     {
  51.         $em $this->em;
  52.         $User $em->getRepository(Users::class)->findOneBy(array('username' => 'admin'));
  53.         if(is_object($User)){
  54.             $token = new UsernamePasswordToken($User'main',$User->getRoles());
  55.             $this->tokenStorage->setToken($token);
  56.         }
  57.         return $this->render("index.html.twig");
  58.     }
  59.     /**
  60.      * @Route("/auth_create", name="auth_create")
  61.      */
  62.     public function auth_create()
  63.     {
  64.         $em $this->em;
  65.         $User = new Users();
  66.         $User->setFullName("admin");
  67.         $User->setUsername("admin");
  68.         $User->setEmail("admin@example.com");
  69.         $User->setRoles(array("ROLE_ADMIN"));
  70.         $plaintextPassword "123123";
  71.         // hash the password (based on the security.yaml config for the $user class)
  72.         $hashedPassword $this->passwordHasher->hashPassword($User$plaintextPassword);
  73.         $User->setPassword($hashedPassword);
  74.         $em->persist($User);
  75.         $em->flush();
  76.         return $this->render("index.html.twig");
  77.     }
  78.     /**
  79.      * @Route("/test_service", name="test_service")
  80.      */
  81.     public function test_service()
  82.     {
  83.         $em $this->em;
  84.         $res $this->testService->hello();
  85.         echo $res;
  86.         die();
  87.         return $this->render("index.html.twig");
  88.     }
  89.     /**
  90.      * @Route("/test_serialization", name="test_serialization")
  91.      */
  92.     public function test_serialization()
  93.     {
  94.         $em $this->em;
  95.         $users $em->getRepository(Users::class)->findAll();
  96.         $dataUsers $this->serializationService->serialize($users);
  97.         echo "<pre>";
  98.         var_export($dataUsers);
  99.         die();
  100.     }
  101.     /**
  102.      * @Route("/test_mail", name="test_serialization")
  103.      */
  104.     public function test_mail()
  105.     {
  106.         $arrayParamMail = array(
  107.             'full_name' => 'Tarik SERRAKH',
  108.             'code' => '123123'
  109.         );
  110.         $body $this->renderView('mailing/demos/mail_demo.html.twig'$arrayParamMail);
  111.         $this->mailService->setSubject('Test TRK Objet');
  112.         //$this->mailService->setText('Hello TRK');
  113.         $this->mailService->setBody($body);
  114.         $this->mailService->setFrom('noreplay@e-ambition.com''E-AMBITION');
  115.         $this->mailService->addAddress('tarik.serrakh@gmail.com''Tarik SERRAKH');
  116.         $this->mailService->addAddress('eambition.sarl@gmail.com''EA');
  117.         //$this->mailService->addAttachment('https://cdn.tictacsante.com/assets/images/doc/covers/cover-02DSQ454D5S4DD5Q4.jpg');
  118.         $this->mailService->Dispatcher();
  119.         return $this->render("index.html.twig");
  120.     }
  121. }