Beispiel #1
0
 /**
  * @Route("/account/create", name="account_create_process")
  * @Method("POST")
  */
 public function createProcessAction(Request $request)
 {
     $form = $this->createForm(new NewAccountType(), $newAccountData = new NewAccountData());
     $form->submit($request);
     if ($form->isValid()) {
         if ($this->getRequest()->isXmlHttpRequest()) {
             return new JsonResponse(array('success' => true));
         }
         $accountData = $newAccountData->getCustomer();
         /** @var EntityManager $em */
         $em = $this->container->get('doctrine')->getManager();
         $title = $em->getRepository('SehBundle:Customer\\Title')->find($accountData->getTitle());
         $customer = new Customer();
         $customer->setTitle($title);
         $customer->setGalittTitle($title->getGalittTitle()->getValue());
         $accountData->toUser($customer);
         $customer->setLoyalty($newAccountData->getLoyalty());
         $customer->setActive(false);
         $customer->setToken(hash('sha512', $customer->getLastName() . ' ' . $customer->getFirstName() . ' ' . $customer->getEmail()));
         if ($newAccountData->getAccentCard()) {
             $customer->setTempCardNumber($newAccountData->getAccentCard());
         }
         $em->persist($customer);
         try {
             /** @var Translator $translator */
             $translator = $this->get('translator');
             $subject = $translator->trans('receipt.email.account.create.subject');
             $mailParams = $this->container->getParameter('emails');
             $body = $this->renderView('SehBundle:mails:account_validation.html.twig', array('title' => $customer->getTitle(), 'fullName' => ucfirst($customer->getLastName()) . ' ' . ucfirst($customer->getFirstName()), 'token' => $customer->getToken(), 'subject' => $subject));
             $mailNewAccount = \Swift_Message::newInstance()->setContentType('text/html')->setFrom(array($mailParams['booking']['sender_mail'] => $mailParams['booking']['sender_name']))->addTo($customer->getEmail())->setSubject($subject)->setBody($body);
             $this->get('mailer')->send($mailNewAccount);
             $this->container->get('session')->getFlashBag()->add('success', 'form.create_account.email.sent.account.to.activate');
             // Checking Token Facebook
             $this->get('seh.facebook_manager')->setFacebookSessionByCustomer($customer);
             $em->flush();
         } catch (\Exception $e) {
             $this->container->get('logger')->error($e->getMessage());
         }
     }
     if ($this->getRequest()->isXmlHttpRequest()) {
         return new JsonResponse(array('success' => false, 'errors' => $this->getFormErrorsAsArray($form)));
     }
     if (in_array($this->get('kernel')->getEnvironment(), array('mobile', 'mobile_dev'))) {
         return new RedirectResponse($this->generateUrl('account_login'));
     } else {
         return new RedirectResponse($this->generateUrl('account_create'));
     }
 }