/** * @Route("/send_accent_card", name="send_accent_card") * @Method("POST") */ function sendContactAction(Request $request) { $accentCardData = new AccentCardDemande(); $validationAccentCardForm = $this->createForm('seh_bundle_accent_card_create', $accentCardData); $validationAccentCardForm->submit($request); /** @var EntityManager $em */ $em = $this->container->get('doctrine')->getManager(); /** @var Session $session */ $session = $this->get('session'); $customer = $em->getRepository('SehBundle:Customer')->findOneByEmail($accentCardData->getEmail()); if ($validationAccentCardForm->isValid()) { if ($this->getRequest()->isXmlHttpRequest()) { return new JsonResponse(array('success' => true)); } if (!$customer) { try { $title = $accentCardData->getTitle(); $customer = new Customer(); $customer->setTitle($title); $customer->setGalittTitle($title->getGalittTitle()->getValue()); $accentCardData->toUser($customer); $customer->setLoyalty(1); $customer->setActive(false); $customer->setToken(hash('sha512', $customer->getLastName() . ' ' . $customer->getFirstName() . ' ' . $customer->getEmail())); if ($accentCardData->getAccentCardNumber()) { $customer->setTempCardNumber($accentCardData->getAccentCardNumber()); } $em->persist($customer); try { // Send AR to Customer $mailParams = $this->container->getParameter('emails'); $body = $this->renderView('SehBundle:receipt:email-loyalty-form.html.twig', array('data' => $accentCardData, 'token' => $customer->getToken())); $mailNewAccount = \Swift_Message::newInstance()->setContentType('text/html')->setFrom(array($mailParams['booking']['sender_mail'] => $mailParams['booking']['sender_name']))->addTo($customer->getEmail())->setSubject($this->get('translator')->trans('receipt.email.loyalty.form.subject'))->setBody($body); $this->get('mailer')->send($mailNewAccount); $em = $this->getDoctrine()->getManager(); $em->persist($accentCardData); $em->flush(); $flashBody = $this->renderView('SehBundle:receipt:loyalty-form.html.twig'); $session->getFlashBag()->add('success', $flashBody); } catch (\Exception $e) { $this->container->get('logger')->error($e->getMessage()); $session->getFlashBag()->add('error', 'accent.card.account.error'); } } catch (\Exception $e) { $this->container->get('logger')->error(sprintf('An error occured while trying to update a password from a customer email on Galitt. Request failed with message : "%s"', $e->getMessage())); $session->getFlashBag()->add('error', 'accent.card.account.error'); } } else { $session->getFlashBag()->add('error', 'accent.card.account.already.exist'); } } $formErrors = $this->getFormErrorsAsArray($validationAccentCardForm); if ($this->getRequest()->isXmlHttpRequest()) { return new JsonResponse(array('success' => false, 'errors' => $formErrors)); } return new RedirectResponse($this->getRequest()->headers->get('referer')); }
/** * @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')); } }
/** * @param $response * @return Customer Returns a Customer entity with data based on the response from getAccountFidelity webservice */ protected function createCustomerFromResponse($response) { if (!($customer = $this->entityManager->getRepository('SehBundle:Customer')->findOneByEmail($response->emailClient))) { $customer = new Customer(); } if (!$customer->getAccountOption()) { $customer->setAccountOption($response->nlCarteFidelite); } if (!$customer->getAddress()) { $customer->setAddress($response->adresseClient); } if (!$customer->getAddress2()) { $customer->setAddress2($response->cplAdresseClient); } if (!$customer->getBirthDate() && ($birthdate = \DateTime::createFromFormat('Ymd', $response->dateNaissance))) { $customer->setBirthDate($birthdate); } if (!$customer->getCity()) { $customer->setCity($response->villeClient); } if (!$customer->getCountry()) { $customer->setCountry($response->paysClient); } if (!$customer->getPhone()) { $customer->setPhone($response->telephone); } if (!$customer->getFirstName()) { $customer->setFirstName($response->prenom); } if (!$customer->getLastName()) { $customer->setLastName($response->nom); } if (!$customer->getMobile()) { $customer->setMobile($response->mobile); } if (!$customer->getLocale()) { $customer->setLocale($response->langueClient); } if (!$customer->getEmail()) { $customer->setEmail($response->emailClient); } if (!$customer->getZipCode()) { $customer->setZipCode($response->cpClient); } $customer->setGalittTitle($response->civilite); if (!$customer->getTitle()) { if ($galittTitle = $this->entityManager->getRepository('SehBundle:Customer\\GalittTitle')->findOneByValue($response->civilite)) { $customer->setTitle($galittTitle->getTitle()); } } $hasMainCard = $customer->getMainAccentCard(); foreach (explode(',', $response->listeCarteFidelite) as $accentCardNumber) { $cardResponse = $this->getCardInfo($accentCardNumber); if ($cardResponse) { $accentCard = $this->createAccentCardFromResponse($cardResponse, $accentCardNumber); if (AccentCard::ACTIF == $accentCard->getStatus() && !$hasMainCard) { $accentCard->setMainCard(true); $hasMainCard = true; } $customer->addAccentCard($accentCard); $accentCard->setCustomer($customer); } } if (!$hasMainCard && count($customer->getAccentCards()) > 0) { /** @var AccentCard $accentCard */ $accentCard = $customer->getAccentCards()[0]; if ($accentCard) { $accentCard->setMainCard(true); } } return $customer; }
/** * @Route("/confirmation", name="booking_step_five", schemes={"https"}) */ public function stepFiveAction() { $step = 5; $bookingUserSelection = $this->getCurrentBooking(); if (!$bookingUserSelection->isStepValid(5) && !$bookingUserSelection->getProcessed()) { $this->get('session')->getFlashBag()->add('notice', 'booking.session.unvalidated'); return $this->redirect($this->generateUrl('booking_step_one', array('bookingId' => $bookingUserSelection->getBookingId()))); } $bookingManager = $this->getBookingManager(); $hotel = $bookingManager->getHotel(); $em = $this->getDoctrine()->getManager(); $accentCard = ''; $accountData = new AccountData(); $user = null; if ($bookingUserSelection->getAuthMode() == BookingUserSelection::BOOKING_AUTH_MOD_NEW_ACCOUNT) { $newAccountData = $bookingUserSelection->getNewAccountData(); $accountData = $newAccountData->getCustomer(); $title = $em->getRepository('SehBundle:Customer\\Title')->find($accountData->getTitle()); if (!$bookingUserSelection->getCreatedCustomer()) { $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())); $em->persist($customer); $em->flush(); $bookingUserSelection->setCreatedCustomer(true); $bookingManager->saveBookingToSession($bookingUserSelection); try { $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' => '[Société Européenne d\'Hôtellerie] Validation de votre compte')); $mailNewAccount = \Swift_Message::newInstance()->setContentType('text/html')->setFrom(array($mailParams['booking']['sender_mail'] => $mailParams['booking']['sender_name']))->addTo($customer->getEmail())->setSubject("[Société Européenne d'Hôtellerie] Validation de votre compte")->setBody($body); $this->get('mailer')->send($mailNewAccount); } catch (\Exception $e) { $this->container->get('logger')->error($e->getMessage()); } } } elseif ($bookingUserSelection->getAuthMode() == BookingUserSelection::BOOKING_AUTH_MOD_LOGGED_OFF) { $accountData = $bookingUserSelection->getNoAccountData(); } elseif ($bookingUserSelection->getAuthMode() == BookingUserSelection::BOOKING_AUTH_MOD_LOGGED_IN) { $accountData = new AccountData(); $accountData->fromUser($user = $this->getUser()); } $title = $this->getRepository('SehBundle:Customer\\Title')->find($accountData->getTitle()); $reservationErrors = $bookingUserSelection->getReservationErrors(); $bookingUserSelection->setReservationErrors(array()); $bookingManager->saveBookingToSession($bookingUserSelection); $booking = $this->getRepository('SehBundle:Booking\\Booking')->findOneByBookingId($bookingUserSelection->getBookingId()); if ($user) { $accentCard = $this->getRepository('SehBundle:Customer\\AccentCard')->findOneByUserMainCard($user); } $bookingId = $this->getRequest()->query->get('bookingId'); $refererLinkKnowMore = '?referer=booking_step_five&bookingId=' . $bookingId; return $this->renderForBooking('MobileBundle:booking:step.five.html.twig', array('civility' => $title, 'customer' => $accountData, 'step' => $step, 'hotel' => $hotel, 'booking' => $booking, 'errors' => $reservationErrors, 'backLink' => $bookingManager->getReferer(), 'accentCard' => $user ? $accentCard : false, 'refererLinkKnowMore' => $refererLinkKnowMore)); }