src/Controller/DefaultController.php line 17

Open in your IDE?
  1. <?php
  2. // src/Controller/LuckyController.php
  3. namespace App\Controller;
  4. use App\Form\ContactType;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use ReCaptcha\ReCaptcha;
  10. class DefaultController extends AbstractController
  11. {
  12. /**
  13. * @Route("/", name="homepage")
  14. */
  15. public function indexAction(Request $request)
  16. {
  17. // replace this example code with whatever you need
  18. return $this->render('index.html.twig');
  19. }
  20. /**
  21. * @Route("/image-to-base64", name="image-to-base64")
  22. */
  23. public function image_to_base64()
  24. {
  25. return $this->render('image-to-base64.html.twig');
  26. }
  27. /**
  28. * @Route("/base64-to-image", name="base64-to-image")
  29. */
  30. public function base64_to_image()
  31. {
  32. return $this->render('base64-to-image.html.twig');
  33. }
  34. /**
  35. * @Route("/text-to-base64", name="text-to-base64")
  36. */
  37. public function text_to_base64()
  38. {
  39. return $this->render('text-to-base64.html.twig');
  40. }
  41. /**
  42. * @Route("/base64-to-text", name="base64-to-text")
  43. */
  44. public function base64_to_text()
  45. {
  46. return $this->render('base64-to-text.html.twig');
  47. }
  48. /**
  49. * @Route("/pdf-to-base64", name="pdf-to-base64")
  50. */
  51. public function pdf_to_base64()
  52. {
  53. return $this->render('pdf-to-base64.html.twig');
  54. }
  55. /**
  56. * @Route("/base64-to-pdf", name="base64-to-pdf")
  57. */
  58. public function base64_to_pdf()
  59. {
  60. return $this->render('base64-to-pdf.html.twig');
  61. }
  62. /**
  63. * @Route("/audio-to-base64", name="audio-to-base64")
  64. */
  65. public function audio_to_base64()
  66. {
  67. return $this->render('audio-to-base64.html.twig');
  68. }
  69. /**
  70. * @Route("/base64-to-audio", name="base64-to-audio")
  71. */
  72. public function base64_to_audio()
  73. {
  74. return $this->render('base64-to-audio.html.twig');
  75. }
  76. /**
  77. * @Route("/programming-examples", name="programming-examples")
  78. */
  79. public function programming_examples()
  80. {
  81. return $this->render('programming-examples.html.twig');
  82. }
  83. /**
  84. * @Route("/privacy-policy", name="privacy-policy")
  85. */
  86. public function privacy_policy()
  87. {
  88. return $this->render('privacy-policy.html.twig');
  89. }
  90. /**
  91. * @Route("/contact-us", name="contact-us", methods={"GET","POST"})
  92. */
  93. public function postContact(Request $request, \Swift_Mailer $mailer)
  94. {
  95. $form = $this->createForm(ContactType::class);
  96. $form->handleRequest($request);
  97. if ($request->isMethod('get')) {
  98. return $this->render('contact-us.html.twig', [
  99. 'email_form' => $form->createView(),
  100. ]);
  101. }else if ($request->isMethod('post')) {
  102. $recaptcha = new ReCaptcha('6LerPaMUAAAAABuEL22KklRGOp1_9N_dZwesFMMY');
  103. $resp = $recaptcha->verify($request->request->get('g-recaptcha-response'), $request->getClientIp());
  104. if ($resp->isSuccess() && $form->isSubmitted() && $form->isValid()) {
  105. $contactFormData = $form->getData();
  106. $message = (new \Swift_Message('New contact from ToBase64!'))
  107. ->setFrom($contactFormData['fromEmail'])
  108. ->setTo('admin@tobase64.dev')
  109. ->setBody($contactFormData['fullName']."\r\n".
  110. $contactFormData['message'],
  111. 'text/plain'
  112. )
  113. ;
  114. $mailer->send($message);
  115. $this->addFlash('success', 'Message was send, thank you!!');
  116. return $this->redirectToRoute('contact-us');
  117. // Do something if the submit wasn't valid ! Use the message to show something
  118. }else{
  119. // Everything works good ;) your contact has been saved.
  120. $this->addFlash('warning', 'Something has failed, we are trying to solve it!!');
  121. return $this->redirectToRoute('contact-us');
  122. }
  123. }
  124. }
  125. }