/** * @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')); } }
/** * @Route("/identification/new_account/process", name="booking_step_three_new_account_process", schemes={"https"}) * @Method("POST") */ public function processNewAccountForm(Request $request) { $newAccountForm = $this->createForm(new NewAccountType(), $newAccountData = new NewAccountData()); $newAccountForm->submit($request); if ($request->hasSession('facebook.session')) { $facebookSession = $request->getSession()->get('facebook.session'); $newAccountData->getCustomer()->setFacebookToken(sha1($facebookSession['id'] . 'sehc2is')); } $bookingManager = $this->getBookingManager(); $bookingUserSelection = $this->getCurrentBooking(); if ($bookingUserSelection->getProcessed()) { return new JsonResponse(array('success' => true)); } $bookingUserSelection->setNewAccountData($newAccountData); $bookingManager->saveBookingToSession($bookingUserSelection); if ($newAccountForm->isValid()) { if ($request->isXmlHttpRequest()) { return new JsonResponse(array('success' => true)); } } if ($request->isXmlHttpRequest()) { return new JsonResponse(array('success' => false)); } $bookingUserSelection->validateStep(3); $bookingManager->saveBookingToSession($bookingUserSelection); return new RedirectResponse($this->generateUrl('booking_step_four', array('bookingId' => $bookingUserSelection->getBookingId()))); }