Example #1
0
 /**
  * @param Customer $object
  * @param Constraint $constraint
  */
 public function validate($object, Constraint $constraint)
 {
     /** @var CustomerRepository $customerRepo */
     $customerRepo = $this->entityManager->getRepository('SehBundle:Customer');
     if ($customerRepo->emailExists($object->getEmail(), $object->getId())) {
         $this->context->addViolationAt('seh_bundle_sehbundle_account_customer_type.email', $constraint->message);
     }
 }
 /**
  * @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'));
 }
Example #3
0
 public function setFacebookSessionByCustomer(Customer $customer)
 {
     if ($this->session->has('facebook.session') && !$customer->getFacebookToken()) {
         $facebookSession = $this->session->get('facebook.session');
         $customer->setFacebookToken(sha1($facebookSession['id'] . 'sehc2is'));
         $this->entityManager->persist($customer);
         $this->entityManager->flush();
     }
 }
Example #4
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'));
     }
 }
Example #5
0
 /**
  * @param Customer $customer
  */
 public function toUser(Customer $customer)
 {
     $customer->setLastName($this->name);
     $customer->setFirstName($this->firstName);
     $customer->setPhone($this->phone);
     $customer->setEmail($this->email);
     $customer->setAddress($this->address);
     $customer->setAddress2($this->address2);
     $customer->setZipCode($this->zipcode);
     $customer->setCity($this->city);
     $customer->setCountry($this->country);
     $customer->setTempCardNumber($this->accentCardNumber);
 }
Example #6
0
 /**
  * @param Customer $customer
  */
 public function toUser(Customer $customer)
 {
     $customer->setLastName($this->lastName);
     $customer->setFirstName($this->firstName);
     $customer->setPhone($this->phone);
     $customer->setBirthDate($this->birthDate);
     $customer->setEmail($this->email);
     $customer->setAddress($this->address);
     $customer->setAddress2($this->address2);
     $customer->setZipCode($this->zipCode);
     $customer->setCity($this->city);
     $customer->setCountry($this->country);
     $customer->setLocale($this->locale);
     $customer->setFacebookToken($this->facebookToken);
 }
Example #7
0
 protected function customerToArray(Customer $customer)
 {
     $toReturn = array();
     $mainAccentCard = $customer->getMainAccentCard();
     $toReturn['numC'] = $mainAccentCard ? $mainAccentCard->getNumber() : '';
     $toReturn['nom'] = $customer->getLastName();
     $toReturn['prenom'] = $customer->getFirstName();
     $toReturn['telephone'] = $customer->getPhone();
     $toReturn['mobile'] = $customer->getMobile() ?: '';
     $toReturn['email'] = $customer->getEmail();
     $toReturn['adresse'] = $customer->getAddress();
     $toReturn['cplAdresse'] = $customer->getAddress2() ?: '';
     $toReturn['codePostal'] = $customer->getZipCode();
     $toReturn['ville'] = $customer->getCity();
     $toReturn['pays'] = $customer->getCountry();
     $toReturn['langue'] = $customer->getLocale();
     $toReturn['civilite'] = $customer->getGalittTitle() ?: $customer->getTitle()->getGalittTitle()->getValue();
     $toReturn['nlCarteFidelite'] = $customer->getAccountOption() ? $customer->getAccountOption() : 'O';
     $toReturn['dateNaissance'] = $customer->getBirthDate() ? $customer->getBirthDate()->format('Ymd') : '19700101';
     return $toReturn;
 }
Example #8
0
 protected function createToken($firewall, Customer $user)
 {
     return new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
 }
Example #9
0
 /**
  * @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));
 }
Example #10
0
 /**
  * @param Customer $customer
  * @param $accentCardNumber
  * @return bool
  */
 public function removeAccentCard(Customer $customer, $accentCardNumber)
 {
     $galittProvider = $this->galittProvider;
     $found = false;
     /** @var Customer\AccentCard $accentCard */
     foreach ($customer->getAccentCards() as $accentCard) {
         if ($accentCard->getNumber() == $accentCardNumber) {
             $customer->removeAccentCard($accentCard);
             $found = true;
         }
     }
     if ($found) {
         try {
             $galittProvider->updateAccountFidelity($customer);
         } catch (\Exception $e) {
             return false;
         }
     }
     return true;
 }