Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Routing\Annotation\Route;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use App\Form\InvitationType;
- use App\Entity\Invitation;
- /**
- * Controller used to manage current user.
- *
- * @author Rakini yassine <rakiniyassine@gmail.com>
- */
- class InviteController extends Controller
- {
- /**
- * @var Swift_Mailer
- */
- private $mailer;
- /**
- * Constructor.
- *
- * @param Swift_Mailer $mailer
- */
- public function __construct(\Swift_Mailer $mailer)
- {
- $this->mailer = $mailer;
- }
- /**
- * @Route("/invite", name="send_invite" )
- * @Security("is_granted('ROLE_MANAGER')")
- */
- public function send(Request $request): Response
- {
- var_dump($this->sendMail('rakiniyassine@gmail.com','#'));
- die();
- $invite = new Invitation();
- $roles=$this->container->getParameter('security.role_hierarchy.roles');
- $form = $this->createForm(InvitationType::class, $invite,[
- 'roles'=>$roles
- ]);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $em = $this->getDoctrine()->getManager();
- $invite->setCreatedBy($this->getUser());
- $em->persist($invite);
- $em->flush();
- }
- return $this->render('front/invite/new.html.twig',[
- 'form'=>$form->createView()
- ]);
- }
- private function sendMail($email, $link)
- {
- $message = (new \Swift_Message('Someone invites you to join crm'))
- ->setFrom('hello@xxx.com')
- ->setTo($email)
- ->setBody(
- $this->renderView('emails/invitation.html.twig', ['email' => $email, 'register_link' => $link]),
- 'text/html');
- return $this->mailer->send($message);
- }
- }
- #swiftmailer:
- # url: '%env(MAILER_URL)%'
- # spool: { type: 'memory' }
- swiftmailer:
- transport: smtp
- auth_mode: login
- host: mail.bionicgymapp.com
- encryption: ssl
- port: 465
- username: hello@xxx.com
- password: xxx'
- spool: { type: memory }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement