SHARE
TWEET

Untitled

a guest Jun 12th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Controller;
  4.  
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use App\Form\InvitationType;
  13. use App\Entity\Invitation;
  14.  
  15. /**
  16.  * Controller used to manage current user.
  17.  *
  18.  * @author Rakini yassine <rakiniyassine@gmail.com>
  19.  */
  20. class InviteController extends Controller
  21. {
  22.  
  23.     /**
  24.     * @var Swift_Mailer
  25.     */
  26.     private $mailer;
  27.  
  28.     /**
  29.      * Constructor.
  30.      *
  31.      * @param Swift_Mailer     $mailer
  32.      */
  33.     public function __construct(\Swift_Mailer $mailer)
  34.     {
  35.         $this->mailer = $mailer;
  36.     }
  37.  
  38.     /**
  39.      * @Route("/invite", name="send_invite" )
  40.      * @Security("is_granted('ROLE_MANAGER')")
  41.      */
  42.     public function send(Request $request): Response
  43.     {
  44.       var_dump($this->sendMail('rakiniyassine@gmail.com','#'));
  45.       die();
  46.       $invite = new Invitation();
  47.  
  48.       $roles=$this->container->getParameter('security.role_hierarchy.roles');
  49.       $form = $this->createForm(InvitationType::class, $invite,[
  50.         'roles'=>$roles
  51.       ]);
  52.  
  53.       $form->handleRequest($request);
  54.       if ($form->isSubmitted() && $form->isValid()) {
  55.         $em = $this->getDoctrine()->getManager();
  56.         $invite->setCreatedBy($this->getUser());
  57.         $em->persist($invite);
  58.         $em->flush();
  59.  
  60.       }
  61.       return $this->render('front/invite/new.html.twig',[
  62.         'form'=>$form->createView()
  63.       ]);
  64.     }
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.     private function sendMail($email, $link)
  72.      {
  73.  
  74.           $message = (new \Swift_Message('Someone invites you to join crm'))
  75.                  ->setFrom('hello@xxx.com')
  76.                  ->setTo($email)
  77.                  ->setBody(
  78.                  $this->renderView('emails/invitation.html.twig', ['email' => $email, 'register_link' => $link]),
  79.                 'text/html');
  80.  
  81.  
  82.          return $this->mailer->send($message);
  83.  
  84.      }
  85.  
  86.  
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. #swiftmailer:
  106. #    url: '%env(MAILER_URL)%'
  107. #    spool: { type: 'memory' }
  108.  
  109. swiftmailer:
  110.     transport: smtp
  111.     auth_mode: login
  112.     host: mail.bionicgymapp.com
  113.     encryption: ssl
  114.     port: 465
  115.     username: hello@xxx.com
  116.     password: xxx'
  117.     spool: { type: memory }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top