<?php
// src/Controller/LuckyController.php
namespace App\Controller;
use App\Form\ContactType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use ReCaptcha\ReCaptcha;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
// replace this example code with whatever you need
return $this->render('index.html.twig');
}
/**
* @Route("/image-to-base64", name="image-to-base64")
*/
public function image_to_base64()
{
return $this->render('image-to-base64.html.twig');
}
/**
* @Route("/base64-to-image", name="base64-to-image")
*/
public function base64_to_image()
{
return $this->render('base64-to-image.html.twig');
}
/**
* @Route("/text-to-base64", name="text-to-base64")
*/
public function text_to_base64()
{
return $this->render('text-to-base64.html.twig');
}
/**
* @Route("/base64-to-text", name="base64-to-text")
*/
public function base64_to_text()
{
return $this->render('base64-to-text.html.twig');
}
/**
* @Route("/pdf-to-base64", name="pdf-to-base64")
*/
public function pdf_to_base64()
{
return $this->render('pdf-to-base64.html.twig');
}
/**
* @Route("/base64-to-pdf", name="base64-to-pdf")
*/
public function base64_to_pdf()
{
return $this->render('base64-to-pdf.html.twig');
}
/**
* @Route("/audio-to-base64", name="audio-to-base64")
*/
public function audio_to_base64()
{
return $this->render('audio-to-base64.html.twig');
}
/**
* @Route("/base64-to-audio", name="base64-to-audio")
*/
public function base64_to_audio()
{
return $this->render('base64-to-audio.html.twig');
}
/**
* @Route("/programming-examples", name="programming-examples")
*/
public function programming_examples()
{
return $this->render('programming-examples.html.twig');
}
/**
* @Route("/privacy-policy", name="privacy-policy")
*/
public function privacy_policy()
{
return $this->render('privacy-policy.html.twig');
}
/**
* @Route("/contact-us", name="contact-us", methods={"GET","POST"})
*/
public function postContact(Request $request, \Swift_Mailer $mailer)
{
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
if ($request->isMethod('get')) {
return $this->render('contact-us.html.twig', [
'email_form' => $form->createView(),
]);
}else if ($request->isMethod('post')) {
$recaptcha = new ReCaptcha('6LerPaMUAAAAABuEL22KklRGOp1_9N_dZwesFMMY');
$resp = $recaptcha->verify($request->request->get('g-recaptcha-response'), $request->getClientIp());
if ($resp->isSuccess() && $form->isSubmitted() && $form->isValid()) {
$contactFormData = $form->getData();
$message = (new \Swift_Message('New contact from ToBase64!'))
->setFrom($contactFormData['fromEmail'])
->setTo('admin@tobase64.dev')
->setBody($contactFormData['fullName']."\r\n".
$contactFormData['message'],
'text/plain'
)
;
$mailer->send($message);
$this->addFlash('success', 'Message was send, thank you!!');
return $this->redirectToRoute('contact-us');
// Do something if the submit wasn't valid ! Use the message to show something
}else{
// Everything works good ;) your contact has been saved.
$this->addFlash('warning', 'Something has failed, we are trying to solve it!!');
return $this->redirectToRoute('contact-us');
}
}
}
}