src/Framework/FrontBundle/Controller/SecurityController.php line 100

Open in your IDE?
  1. <?php
  2. /*
  3.  *
  4.  * (c) Loïc Haas <loic.haas@outlook.com>
  5.  * http://www.haas-info.com/
  6.  *
  7.  */
  8. namespace App\Framework\FrontBundle\Controller;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Security\Core\Security;
  14. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  15. use Symfony\Component\Security\Http\Util\TargetPathTrait;
  16. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  17. use App\Framework\AppBundle\Entity\User;
  18. use App\Security\LoginFormAuthenticator;
  19. use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
  20. use Symfony\Component\Mailer\MailerInterface;
  21. use Symfony\Component\Mime\Email;
  22. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  23. class SecurityController extends AbstractController
  24. {
  25.     use TargetPathTrait;
  26.     private $urlGenerator;
  27.     public function __construct(UrlGeneratorInterface $urlGenerator)
  28.     {
  29.         $this->urlGenerator $urlGenerator;
  30.     }
  31.     /**
  32.      * @Route("/login", name="security_login")
  33.      * @Route("/{locale}/security_login", name="security_login_locale", requirements={"locale" = "([a-z\-0-9]+)"})
  34.      */
  35.     public function login(Request $requestSecurity $securityAuthenticationUtils $helper$locale NULL): Response
  36.     {
  37.       if($locale){
  38.         $request->setLocale($locale);
  39.       }
  40.         // if user is already logged in, don't display the login page again
  41.         if ($security->isGranted('ROLE_MANAGER')) {
  42.             return $this->redirectToRoute('framework_admin_dashboard_index');
  43.         } elseif ($security->isGranted('ROLE_ADMIN')) {
  44.             return $this->redirectToRoute('framework_admin_dashboard_index');
  45.         } elseif ($security->isGranted('ROLE_USER')) {
  46.             return $this->redirectToRoute('framework_front_account_histo', ['locale' => $request->getLocale()]);
  47.         }
  48.         // this statement solves an edge-case: if you change the locale in the login
  49.         // page, after a successful login you are redirected to a page in the previous
  50.         // locale. This code regenerates the referrer URL whenever the login page is
  51.         // browsed, to ensure that its locale is always the current one.
  52.         // $this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin_index'));
  53.         $metaDesc 'Bienvenue dans votre espace';
  54.         $metaTitle 'Se connecter';
  55.           
  56.         if($locale == 'de'){
  57.           $metaDesc 'Willkommen in Ihrem Mitgliederbereich';
  58.           $metaTitle 'Sich anmelden';
  59.         }
  60.         if($locale == 'en'){
  61.           $metaDesc 'Welcome to your member area';
  62.           $metaTitle 'Login';
  63.         }
  64.         return $this->render('AdminBundle/Security/login.html.twig', [
  65.             // last username entered by the user (if any)
  66.             'last_username' => $helper->getLastUsername(),
  67.             // last authentication error (if any)
  68.             'error' => $helper->getLastAuthenticationError(),
  69.             'metaTitle' => $metaTitle,
  70.             'metaDesc' => $metaDesc,
  71.         ]);
  72.     }
  73.     /**
  74.      * @Route("/backoffrp/login", name="security_login_admin")
  75.      */
  76.     public function loginAdmin(Request $requestSecurity $securityAuthenticationUtils $helper): Response
  77.     {
  78.         // if user is already logged in, don't display the login page again
  79.         if ($security->isGranted('ROLE_MANAGER')) {
  80.             return $this->redirectToRoute('framework_admin_dashboard_index');
  81.         } elseif ($security->isGranted('ROLE_ADMIN')) {
  82.             return $this->redirectToRoute('framework_admin_dashboard_index');
  83.         }
  84.         // this statement solves an edge-case: if you change the locale in the login
  85.         // page, after a successful login you are redirected to a page in the previous
  86.         // locale. This code regenerates the referrer URL whenever the login page is
  87.         // browsed, to ensure that its locale is always the current one.
  88.         // $this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin_index'));
  89.         return $this->render('AdminBundle/Security/login_admin.html.twig', [
  90.             // last username entered by the user (if any)
  91.             'last_username' => $helper->getLastUsername(),
  92.             // last authentication error (if any)
  93.             'error' => $helper->getLastAuthenticationError(),
  94.         ]);
  95.     }
  96.     /**
  97.      * This is the route the user can use to logout.
  98.      *
  99.      * But, this will never be executed. Symfony will intercept this first
  100.      * and handle the logout automatically. See logout in config/packages/security.yaml
  101.      *
  102.      * @Route("/logout", name="security_logout")
  103.      */
  104.     public function logout(): void
  105.     {
  106.         throw new \Exception('This should never be reached!');
  107.     }
  108.     /**
  109.      * This is the route the user can use to logout.
  110.      *
  111.      * But, this will never be executed. Symfony will intercept this first
  112.      * and handle the logout automatically. See logout in config/packages/security.yaml
  113.      *
  114.      * @Route("/backoffrp/logout", name="security_logout_admin")
  115.      */
  116.     public function logoutAdmin(): void
  117.     {
  118.         throw new \Exception('This should never be reached!');
  119.     }
  120.     /**
  121.      * @Route("/dispatch", name="security_dispatch")
  122.      */
  123.     public function dispatch(Request $requestSecurity $securityAuthenticationUtils $helper): Response
  124.     {
  125.         if ($security->isGranted('ROLE_MANAGER')) {
  126.             return $this->redirectToRoute('framework_admin_dashboard_index');
  127.         } elseif ($security->isGranted('ROLE_ADMIN')) {
  128.             return $this->redirectToRoute('framework_admin_dashboard_index');
  129.         } else {
  130.             return $this->redirectToRoute('framework_front_account_histo', ['locale' => $request->getLocale()]);
  131.         }
  132.     }
  133.     /**
  134.      * @Route("/dispatchadmin", name="security_dispatch_admin")
  135.      */
  136.     public function dispatchadmin(Request $requestSecurity $securityAuthenticationUtils $helper): Response
  137.     {
  138.         // if ($security->isGranted('ROLE_MANAGER')) {
  139.         //     return $this->redirectToRoute('framework_admin_dashboard_index');
  140.         // } elseif ($security->isGranted('ROLE_ADMIN')) {
  141.         //     return $this->redirectToRoute('framework_admin_dashboard_index');
  142.         // } else {
  143.         //     return $this->redirectToRoute('framework_front_account_histo', ['locale' => $request->getLocale()]);
  144.         // }
  145. // exit;
  146.         return $this->redirectToRoute('framework_admin_dashboard_index');
  147.     }
  148.     /**
  149.      * @Route("/mon-compte/infos", name="security_infos")
  150.      * @Route("/mon-compte/infos/{locale}", name="security_infos_locale", requirements={"locale" = "([a-z\-0-9]+)"})
  151.      */
  152.     public function infosAction(Request $requestSecurity $securityUserPasswordEncoderInterface $passwordEncoder$locale NULL)
  153.     {
  154.       if($locale){
  155.         $request->setLocale($locale);
  156.       }
  157.       $tr $this->loadTranslation($locale);
  158.         require_once dirname(__FILE__).'/../../plugins/stripe-php-10.12.1/init.php';
  159.         $em $this->getDoctrine()->getManager();
  160.         $locale $request->getLocale();
  161.         $globals $this->get("twig")->getGlobals();
  162.         $isAjax $request->isXMLHttpRequest();
  163.         if ($isAjax) {
  164.             $error $error_name "";
  165.             $success true;
  166.             if (!$security->isGranted('ROLE_USER')) {
  167.                 $error $tr['signup_error5'];
  168.                 $success false;
  169.             }
  170.             $user $this->getUser();
  171.             $infos $user->getInfos();
  172.             if($infos == null){
  173.               $infos json_decode('{}');
  174.             }
  175.             if( 
  176.                 $request->get('firstname') == '' ||
  177.                 $request->get('lastname') == '' ||
  178.                 $request->get('address1') == '' ||
  179.                 $request->get('zipcode') == '' ||
  180.                 $request->get('city') == '' ||
  181.                 $request->get('country_code') == '' ||
  182.                 $request->get('country') == '' ||
  183.                 $request->get('phone') == ''
  184.             ){
  185.                 $error $tr['contact_error2'];
  186.                 $success false;
  187.                 $error_name 'form';
  188.             }
  189.             if( $request->get('password') != '' ){
  190.                 $passwordValid true;
  191.                 if( $request->get('password') != $request->get('confirm') ){
  192.                     $error $tr['signup_error3'];
  193.                     $success false;
  194.                     $error_name 'confirm';
  195.                     $passwordValid false;
  196.                 }
  197.                 if( strlen($request->get('password')) < ){
  198.                     $error $tr['signup_error2'];
  199.                     $success false;
  200.                     $error_name 'confirm';
  201.                     $passwordValid false;
  202.                 }
  203.                 if( $passwordValid ){
  204.                     $user->setPassword(
  205.                         $passwordEncoder->encodePassword(
  206.                           $user,
  207.                           $request->get('confirm')
  208.                         )
  209.                     );
  210.                     $em->persist($user);
  211.                     $em->flush();
  212.                 }
  213.             }
  214.             if( $success ){
  215.                 $infos->firstname ucwords(strtolower(trim($request->get('firstname'))));
  216.                 $infos->lastname strtoupper(trim($request->get('lastname')));
  217.                 $infos->company trim($request->get('company'));
  218.                 $infos->address1 trim($request->get('address1'));
  219.                 $infos->zipcode trim($request->get('zipcode'));
  220.                 $infos->city ucwords(strtolower(trim($request->get('city'))));
  221.                 $infos->country_code $request->get('country_code');
  222.                 $infos->country ucwords(strtolower(trim($request->get('country'))));
  223.                 $infos->phone trim($request->get('phone'));
  224.                 $user->setInfos(json_encode($infos));
  225.             $stripe = new \Stripe\StripeClient(
  226.               $globals['stripe_secret_key']
  227.             );
  228.             $customer $stripe->customers->update(
  229.               $user->getInfo('stripe_id'),
  230.               [
  231.                 'name' => ucwords(strtolower(trim($request->get('firstname')))).' '.strtoupper(trim($request->get('lastname'))),
  232.                 'address' => [
  233.                   'city' => trim($request->get('city')),
  234.                   'country' => $request->get('country_code'),
  235.                   'line1' => trim($request->get('address1')),
  236.                   // 'line2' => trim($request->get('address_line2')),
  237.                   'postal_code' => trim($request->get('zipcode')),
  238.                 ],
  239.                 'phone' => trim($request->get('phone')),
  240.                 'preferred_locales' =>[strtolower($request->getLocale())],
  241.                 'metadata' => ['company_name' => trim($request->get('company'))]
  242.               ]
  243.             );
  244.                 $em->persist($user);
  245.                 $em->flush();
  246.             }
  247.             $data = [
  248.               'error' => $error,
  249.               'success' => $success,
  250.               'error_name' => $error_name
  251.             ];
  252.             $response = new Response(json_encode($data));
  253.             $response->headers->set('Content-Type''application/json');
  254.             return $response;
  255.         } else {
  256.             return $this->redirectToRoute('security_login');
  257.         }
  258.     }
  259.     /**
  260.      * @Route("/forgot", name="security_forgot")
  261.      * @Route("/forgot/{locale}", name="security_forgot_locale", requirements={"locale" = "([a-z\-0-9]+)"})
  262.      */
  263.     public function forgot(Request $requestMailerInterface $mailer$locale NULL): Response
  264.     {
  265.         if($locale){
  266.           $request->setLocale($locale);
  267.         } else {
  268.           $locale 'fr';
  269.           $request->setLocale('fr');
  270.         }
  271.         $em $this->getDoctrine()->getManager();
  272.         $globals $this->get("twig")->getGlobals();
  273.         $tr $this->loadTranslation($locale);
  274.         $isAjax $request->isXMLHttpRequest();
  275.         if (!$isAjax) {   
  276.             return $this->redirectToRoute('framework_front_page_404', ['locale' => $locale]);
  277.         }
  278.         $success false;
  279.         $error '';
  280.         $user $em->getRepository('FrameworkAppBundle:User')->findOneBy(['email' => $request->get('email')]);
  281.         $forgot $this->randomPassword();
  282.         if( !$user ){
  283.             $error $tr['login_error1'];
  284.         } else {
  285.             $user->setForgot($forgot);
  286.             $em->persist($user);
  287.             $em->flush();
  288.             
  289.             $subject 'Votre compte Royal Palace';
  290.             $title $subject;
  291.             $content '<p>Bonjour,</p>
  292.                                       <strong><a href="'.$this->urlGenerator->generate('security_reset_locale', ['token' => $forgot'locale' => $locale], UrlGeneratorInterface::ABSOLUTE_URL).'">Cliquez ici pour créer un nouveau mot de passe</a></strong>
  293.                                       <p><br>A bientôt au <a href="'.$globals['app_email_domain'].'"><strong>Royal Palace</strong></a></p>';
  294.           if($locale == 'de'){
  295.             $subject 'Ihr Konto bei Royal Palace';
  296.             $title $subject;
  297.             $content '<p>Hallo,</p>
  298.                                       <strong><a href="'.$this->urlGenerator->generate('security_reset_locale', ['token' => $forgot'locale' => $locale], UrlGeneratorInterface::ABSOLUTE_URL).'">Klicken Sie hier, um ein neues Passwort zu erstellen</a></strong>
  299.                                       <p><br>Bis bald im <a href="'.$globals['app_email_domain'].'"><strong>Royal Palace</strong></a></p>';
  300.           }
  301.           if($locale == 'en'){
  302.             $subject 'Your Royal Palace account';
  303.             $title $subject;
  304.             $content '<p>Hello,</p>
  305.                                       <strong><a href="'.$this->urlGenerator->generate('security_reset_locale', ['token' => $forgot'locale' => $locale], UrlGeneratorInterface::ABSOLUTE_URL).'">Click here to create a new password</a></strong>
  306.                                       <p><br>See you soon at the <a href="'.$globals['app_email_domain'].'"><strong>Royal Palace</strong></a></p>';
  307.           }
  308.             //ENVOI EMAIL
  309.             $from $globals['app_email_noreply'];
  310.             $to $globals['app_email_address'];
  311.             $contact $globals['app_email_contact'];
  312.             $email = (new Email())
  313.                 ->from($from)
  314.                 ->to($user->getEmail())
  315.                 //->cc('cc@example.com')
  316.                 //->bcc('bcc@example.com')
  317.                 ->replyTo($contact)
  318.                 //->priority(Email::PRIORITY_HIGH)
  319.                 ->subject($subject)
  320.                 // ->text(nl2br('Royal Palace').nl2br('Royal Palace : Réinitialiser le mot de passe').nl2br('Bonjour,').nl2br('Suivez ce lien pour créer un nouveau mot de passe :').nl2br($this->urlGenerator->generate('security_reset', ['token' => $forgot], UrlGeneratorInterface::ABSOLUTE_URL)).nl2br('A bientôt au Royal Palace'))
  321.                 ->html($this->renderView(
  322.                             'FrontBundle/Emails/general.html.twig', array(
  323.                                     'title'   => $title,
  324.                                     'content' => $content
  325.                                 )
  326.                          ));
  327.             $mailer->send($email);
  328.             //FIN ENVOI EMAIL
  329.             $success true;
  330.         }
  331.         $data = [
  332.           'error' => $error,
  333.           'success' => $success
  334.         ];
  335.         $response = new Response(json_encode($data));
  336.         $response->headers->set('Content-Type''application/json');
  337.         return $response;
  338.     }
  339.     private function randomPassword() {
  340.         $chars "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  341.         return substr(str_shuffle($chars),0,16);
  342.     }
  343.     /**
  344.      * @Route("/reset/{token}", name="security_reset")
  345.      * @Route("/reset/{token}/{locale}", name="security_reset_locale", requirements={"locale" = "([a-z\-0-9]+)"})
  346.      */
  347.     public function reset(string $token NULLRequest $requestSecurity $securityAuthenticationUtils $helper$locale NULL): Response
  348.     {
  349.         if($locale){
  350.           $request->setLocale($locale);
  351.         } else {
  352.           $locale 'fr';
  353.           $request->setLocale('fr');
  354.         }
  355.         if (!$security->isGranted('ROLE_USER') && $token == null) {
  356.             return $this->redirectToRoute('security_login');
  357.         }
  358.         // this statement solves an edge-case: if you change the locale in the login
  359.         // page, after a successful login you are redirected to a page in the previous
  360.         // locale. This code regenerates the referrer URL whenever the login page is
  361.         // browsed, to ensure that its locale is always the current one.
  362.         // $this->saveTargetPath($request->getSession(), 'main', $this->generateUrl('admin_index'));
  363.         $em $this->getDoctrine()->getManager();
  364.         $locale $request->getLocale();
  365.         $tr $this->loadTranslation($locale);
  366.         $globals $this->get("twig")->getGlobals();
  367.         $metaTitle $tr['reset_title'];
  368.         $metaDesc $tr['reset_subtitle'];
  369.         $noindex true;
  370.         if ($security->isGranted('ROLE_USER')){
  371.             $user $this->getUser();
  372.         } else {
  373.             $user $em->getRepository('FrameworkAppBundle:User')->findOneBy(['forgot' => $token]);
  374.         }
  375.         if (!$user) {
  376.             return $this->redirectToRoute('security_login');
  377.         }
  378.         $page $em->getRepository('FrameworkAppBundle:Page')->findOneBy(['slug' => 'connexion''locale' => $locale]);
  379.         return $this->render('AdminBundle/Security/reset.html.twig', [
  380.           'metaTitle' => $metaTitle,
  381.           'metaDesc'  => $metaDesc,
  382.           'noindex'    => $noindex,
  383.             'page' => $page,
  384.             'token' => $token,
  385.         ]);
  386.     }
  387.     /**
  388.      * @Route("/change", name="security_change")
  389.      */
  390.     public function resetChange(Request $requestSecurity $securityUserPasswordEncoderInterface $passwordEncoder)
  391.     {
  392.         $isAjax $request->isXMLHttpRequest();
  393.         if (!$isAjax) {   
  394.             return $this->redirectToRoute('security_login');
  395.         }
  396.         $success false;
  397.         $error '';
  398.         $em $this->getDoctrine()->getManager();
  399.         if($security->isGranted('ROLE_USER')) {
  400.             $user $this->getUser();
  401.             $test_password $passwordEncoder->isPasswordValid($user$request->get('password'));;
  402.             if(!$test_password){
  403.                 $success false;
  404.                 $error 'Mauvais mot de passe';
  405.             } else {
  406.                 $user->setPassword(
  407.                     $passwordEncoder->encodePassword(
  408.                       $user,
  409.                       $request->get('new_password')
  410.                     )
  411.                 );
  412.                 $user->setForgot(NULL);
  413.                 $em->persist($user);
  414.                 $em->flush();
  415.                 $success true;
  416.             }
  417.         } else {
  418.             $user $em->getRepository('FrameworkAppBundle:User')->findOneBy(['forgot' => $request->get('token')]);
  419.             if (!$user) {
  420.                 $success false;
  421.                 $error 'Ce compte n\'existe pas';
  422.             } elseif($request->get('confirm_password') != $request->get('new_password')) {
  423.                 $success false;
  424.                 $error 'La confirmation et le mot de passe ne correspondent pas';
  425.             } else {
  426.                 $user->setPassword(
  427.                     $passwordEncoder->encodePassword(
  428.                       $user,
  429.                       $request->get('new_password')
  430.                     )
  431.                 );
  432.                 $user->setForgot(NULL);
  433.                 $em->persist($user);
  434.                 $em->flush();
  435.                 $success true;
  436.             }
  437.         }
  438.         $data = [
  439.           'error' => $error,
  440.           'success' => $success
  441.         ];
  442.         $response = new Response(json_encode($data));
  443.         $response->headers->set('Content-Type''application/json');
  444.         return $response;
  445.     }
  446.     /**
  447.      * @Route("/signup", name="security_signup")
  448.      * @Route("/signup/{locale}", name="security_signup_locale", requirements={"locale" = "([a-z\-0-9]+)"})
  449.      */
  450.     public function signupAjax(Request $requestUserPasswordEncoderInterface $passwordEncoderLoginFormAuthenticator $loginGuardAuthenticatorHandler $guardMailerInterface $mailer$locale NULL)
  451.     {
  452.         if($locale){
  453.           $request->setLocale($locale);
  454.         } else {
  455.           $locale 'fr';
  456.           $request->setLocale('fr');
  457.         }
  458.       require_once dirname(__FILE__).'/../../plugins/stripe-php-10.12.1/init.php';
  459.       $em $this->getDoctrine()->getManager();
  460.       $globals $this->get("twig")->getGlobals();
  461.       $tr $this->loadTranslation($locale);
  462.       $isAjax $request->isXMLHttpRequest();
  463.       if (!$isAjax) {   
  464.           return $this->redirectToRoute('framework_front_page_404', ['locale' => $locale]);
  465.       }
  466.       $success false;
  467.       $error '';
  468.       if( $em->getRepository('FrameworkAppBundle:User')->findOneBy(['email' => $request->get('email')]) ){
  469.           $error $tr['signup_error1'];
  470.       } elseif($request->get('email') == '' || $request->get('password') == '' || $request->get('confirm') == '') {
  471.           $error $tr['contact_error2'];
  472.       } else {
  473. if(trim($request->get('email')) == 'sample@email.tst'){
  474. exit;
  475. }
  476.           $user = new User();
  477.           $user->setUsername(strtolower(trim($request->get('email'))));
  478.           $user->setEmail(strtolower(trim($request->get('email'))));
  479.           $user->setPassword(
  480.               $passwordEncoder->encodePassword(
  481.                 $user,
  482.                 $request->get('password')
  483.               )
  484.           );
  485.           $user->setDeleted(0);
  486.           $user->setRoles(["ROLE_USER"]);
  487.             $stripe = new \Stripe\StripeClient(
  488.               $globals['stripe_secret_key']
  489.             );
  490.             $customer $stripe->customers->create([
  491.               'email' => strtolower(trim($request->get('email'))),
  492.               // 'name' => ucwords(strtolower(trim($request->get('firstname')))).' '.strtoupper(trim($request->get('lastname'))),
  493.               // 'address' => [
  494.               //   'city' => trim($request->get('address_city')),
  495.               //   'country' => $request->get('address_country'),
  496.               //   'line1' => trim($request->get('address_line1')),
  497.               //   'line2' => trim($request->get('address_line2')),
  498.               //   'postal_code' => trim($request->get('address_postal_code')),
  499.               // ],
  500.               'metadata' => ['user_id' => $user->getId()],
  501.             ]);
  502.           $user->setInfos(json_encode(['stripe_id' => $customer->id]));
  503.           $em->persist($user);
  504.           $em->flush();
  505.       
  506.           $globals $this->get("twig")->getGlobals();
  507.             $subject 'Votre compte Royal Palace';
  508.             $title $subject;
  509.             $content '<p>Bonjour,</p>
  510.                                     <p>Merci beaucoup pour votre inscription. Complétez vos informations de contact dans la section <a href="'.$globals['app_email_domain'].'fr/mon-compte">"Mon Compte"</a>.</p>
  511.                                     <p>Nous vous invitons à découvrir nos spectacles sur notre site. Pour réserver dès maintenant, consultez <a href="'.$globals['app_email_domain'].'fr/reservation"> notre calendrier</a> et laissez vous guider.</p>
  512.                                     <p><br>A bientôt au <a href="'.$globals['app_email_domain'].'"><strong>Royal Palace</strong></a></p>';
  513.           if($locale == 'de'){
  514.             $subject 'Ihr Konto bei Royal Palace';
  515.             $title $subject;
  516.             $content '<p>Hallo,</p>
  517.                                     <p>Vielen Dank für Ihre Anmeldung. Vervollständigen Sie Ihre Kontaktinformationen im Abschnitt <a href="'.$globals['app_email_domain'].'de/mon-compte">"Mein Konto"</a>.</p>
  518.                                     <p>Wir laden Sie ein, unsere Aufführungen auf unserer Website zu entdecken. Um schon jetzt zu buchen, werfen Sie einen Blick auf <a href="'.$globals['app_email_domain'].'de/buchen"> unseren Kalender</a> und lassen Sie sich führen.</p>
  519.                                     <p><br>Bis bald im <a href="'.$globals['app_email_domain'].'de"><strong>Royal Palace</strong></a></p>';
  520.           }
  521.           if($locale == 'en'){
  522.             $subject 'Your Royal Palace account';
  523.             $title $subject;
  524.             $content '<p>Hello,</p>
  525.                                     <p>Thank you very much for registering. Please fill in your contact information in the <a href="'.$globals['app_email_domain'].'en/mon-compte">"My account"</a> section.</p>
  526.                                     <p>We invite you to discover our shows on our website. To book now, consult <a href="'.$globals['app_email_domain'].'en/book"> our calendar</a> and let us guide you.</p>
  527.                                     <p><br>See you soon at the <a href="'.$globals['app_email_domain'].'en"><strong>Royal Palace</strong></a></p>';
  528.           }
  529.           //ENVOI EMAIL
  530.           $from $globals['app_email_noreply'];
  531.           $to $globals['app_email_address'];
  532.           $contact $globals['app_email_contact'];
  533.           $email = (new Email())
  534.               ->from($from)
  535.               ->to($user->getEmail())
  536.               //->cc('cc@example.com')
  537.               //->bcc('bcc@example.com')
  538.               ->replyTo($contact)
  539.               //->priority(Email::PRIORITY_HIGH)
  540.               ->subject($subject)
  541.               // ->text(nl2br('Royal Palace').nl2br('Royal Palace : Inscription').nl2br('Bonjour,').nl2br('Merci beaucoup pour votre inscription. Complétez vos informations de contact dans la section "Mon Compte". Nous vous invitons à découvrir nos spectacles sur notre site. Pour réserver dès maintenant, consultez notre calendrier et laissez vous guider.').nl2br('A bientôt au Royal Palace'))
  542.               ->html($this->renderView(
  543.                           'FrontBundle/Emails/general.html.twig', array(
  544.                                   'title'   => $title,
  545.                                   'content' => $content
  546.                               )
  547.                        ));
  548.           $mailer->send($email);
  549.           //FIN ENVOI EMAIL
  550.           $success true;
  551.           $guard->authenticateUserAndHandleSuccess($user,$request,$login,'main');
  552.       }
  553.       $data = [
  554.         'error' => $error,
  555.         'success' => $success
  556.       ];
  557.       $response = new Response(json_encode($data));
  558.       $response->headers->set('Content-Type''application/json');
  559.       return $response;
  560.     }
  561.   public function loadTranslation($locale){
  562.       $arr = [];
  563.       $em $this->getDoctrine()->getManager();
  564.       $translations $em->getRepository('FrameworkAppBundle:Translation')->findAll();
  565.       foreach ($translations as $key => $translation) {
  566.           $content $translation->getContent();
  567.           if(isset($content[$locale])){
  568.               $arr[$translation->getSlug()] = $content[$locale];
  569.           } else {
  570.               $arr[$translation->getSlug()] = $translation->getSlug();
  571.           }
  572.       }
  573.       return $arr;
  574.   }
  575. }