src/Controller/Front/CustomerController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Session\Session;
  8. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use App\Manager\CustomerManager;
  11. use App\Entity\Customer;
  12. use App\Manager\CartManager;
  13. class CustomerController extends FrontController
  14. {
  15.     
  16.     public function block(CustomerManager $customerMgr)
  17.     {
  18.         $customer $customerMgr->getCustomer();
  19.         return $this->render('front/customer/blocks/header.html.twig', [
  20.             'customer' => $customer
  21.         ]);
  22.     }
  23.     
  24.     /**
  25.      * @Route("/{_locale}/customer/login", name="customer_login")
  26.      */
  27.     public function login(Request $requestCustomerManager $customerMgrSession $session, \Doctrine\ORM\EntityManagerInterface $em, \Symfony\Contracts\Translation\TranslatorInterface $translator)
  28.     {
  29.         $from $request->get('from','index');
  30.         $customer $customerMgr->getCustomer();
  31.         if(!empty($customer))
  32.             return $this->redirectToRoute ('customer_account');
  33.         $loginForm $this->createForm(\App\Form\Customer\LoginType::class,null,[
  34.             'action' => $this->generateUrl('customer_login', ['from'=>$from]),
  35.             'method' => 'POST',
  36.             'translator' => $translator,
  37.             'locale' => $request->getLocale(),
  38.             'attr' => [
  39.                 'novalidate'=>'novalidate'
  40.             ]
  41.         ]);
  42.         $registerForm $this->createForm(\App\Form\Customer\QuickRegisterType::class,null,[
  43.             'action' => $this->generateUrl('customer_login', ['from'=>$from]),
  44.             'method' => 'POST',
  45.             'entity_manager'=>$em,
  46.             'attr' => [
  47.                 'novalidate'=>'novalidate'
  48.             ]
  49.         ]);
  50.         if($request->isMethod('POST')){
  51.             $loginForm->handleRequest($request);
  52.             if($loginForm->isSubmitted()){
  53.                 if($loginForm->isValid()){
  54.                     $data $loginForm->getData();
  55.                     try{
  56.                         $result $customerMgr->login($data['email'], $data['password']);
  57.                         if($result!==false){
  58.                             $status $result->getStatus();
  59.                             if($status == Customer::STATUS_WAITING){
  60.                                 $session->getFlashBag()->add('popup'$translator->trans("Votre demande de création de compte PRO a bien été prise en compte. Notre délai de traitement est de 72h. Au-delà de ce délai, si vous rencontrez des problèmes de connexion, nous vous invitons à contacter le service client au +33 (0)2 47 73 38 38, email : infos@vivog.fr"));
  61.         //                        $tvaForm = $this->createTvaForm($result, $em, $translator, $from);
  62.         //                        $popup = $this->renderView('front/customer/forms/tva.html.twig', [
  63.         //                            'tvaForm' => $tvaForm->createView()
  64.         //                        ]);
  65.         //                        $session->getFlashBag()->add('modal', $popup);
  66.                             }elseif($status == Customer::STATUS_BLOCKED){
  67.                                 $session->getFlashBag()->add('popup'$translator->trans("Votre demande de compte Pro n’a pas pu être validée. Il nous manque des éléments pour valider votre accès PRO. Nous vous invitons à contacter le service client au +33 (0)2 47 73 38 38, email : infos@vivog.fr."));
  68.                             }
  69.                             $priceGroups $result->getPriceGroups();
  70.                             if(count($priceGroups) > 1) {
  71.                                 $msg $this->renderView('front/customer/popups/price-groups/login.html.twig', [
  72.                                     'customer' => $customer,
  73.                                     'priceGroups' => $priceGroups,
  74.                                     'from' => $this->generateUrl($from)
  75.                                 ]);
  76.                                 $session->getFlashBag()->add('popup'$msg);
  77.                             }else if(count($priceGroups) == 1) {
  78.                                 $customerMgr->setPriceContext($priceGroups->first()->getGroup());
  79.                             }
  80.                             return $this->redirectToRoute($from);
  81.                         }else{
  82.                             $session->getFlashBag()->add('error'$translator->trans("Erreur d'identification."));
  83.                         }
  84.                     } catch (\App\Exception\PriceGroupException $ex) {
  85.                         $session->getFlashBag()->add('error'$translator->trans("Vous n'avez accès à aucun type de tarif. <br>Veuillez contacter notre équipe commerciale."));
  86.                     } catch (\Exception $ex) {
  87.                         $session->getFlashBag()->add('error'$translator->trans("Une erreur s'est produite."));
  88.                     }
  89.                 }else{
  90.                     $session->getFlashBag()->add('error'$translator->trans($loginForm->getErrors()));
  91.                 }
  92.             }
  93.             $registerForm->handleRequest($request);
  94.             if($registerForm->isSubmitted() && $registerForm->isValid()){
  95.                 $email strtolower(trim($registerForm->get('email')->getData()));
  96.                 $customer $em->getRepository('App:Customer')->findOneBy(array('email'=>$email));
  97.                 if(!empty($customer)){
  98.                     $session->getFlashBag()->add('error'$translator->trans("Un compte utilisateur utilise déjà l'adresse email : ").$email);
  99.                     return $this->redirectToRoute('customer_login');
  100.                 }
  101.                 $session->set('email'$email);
  102.                 return $this->redirectToRoute('customer_register');
  103.             }
  104.         }
  105.         $tpl 'front/customer/identification.html.twig';
  106.         if(strpos($from'checkout')!==false)
  107.             $tpl 'front/checkout/identification.html.twig';
  108.         return $this->render($tpl, [
  109.             'loginForm' => $loginForm->createView(),
  110.             'registerForm' => $registerForm->createView()
  111.         ]);
  112.     }
  113.     
  114.     /**
  115.      * @Route("/{_locale}/customer/context", name="customer_context")
  116.      */
  117.     public function changeContext(Request $requestCustomerManager $customerMgrCartManager $cartManager, \Doctrine\ORM\EntityManagerInterface $em, \Symfony\Contracts\Translation\TranslatorInterface $translator)
  118.     {
  119.         $ctx $request->get('ctx'false);
  120.         $from $request->get('from'false);
  121.         $confirm $request->get('confirm'false);
  122.         $customer $customerMgr->getCustomer();
  123.         if(empty($from)) {
  124.             $from $this->generateUrl('index');
  125.         }
  126.         if($customer && ctype_alpha($ctx)) {
  127.             $priceGroup $em->getRepository(\App\Entity\PriceGroup::class)->findOneByCode($ctx);
  128.             if($priceGroup) {
  129.                 try{
  130.                     if($confirm == 1) {
  131.                         $cartManager->empty();
  132.                         $customerMgr->setPriceContext($priceGroup);
  133.                         return $this->redirect($from);
  134.                     }else{
  135.                         $msg $this->renderView('front/customer/popups/price-groups/change.html.twig', [
  136.                             'customer' => $customer,
  137.                             'priceGroup' => $priceGroup,
  138.                             'from' => $from
  139.                         ]);
  140.                         $request->getSession()->getFlashBag()->add('popup'$msg);
  141.                     }
  142.                 } catch (Exception $ex) {
  143.                     $request->getSession()->getFlashBag()->add('error'$translator->trans("Vous n'avez accès à aucun type de tarif. <br>Veuillez contacter notre équipe commerciale."));
  144.                 }
  145.             }
  146.         }
  147.         return $this->redirectToRoute('index');
  148.     }
  149.     
  150.     /**
  151.      * @Route("/{_locale}/customer/logout", name="customer_logout")
  152.      */
  153.     public function logout(CustomerManager $customerMgr)
  154.     {
  155.         $customerMgr->logout();
  156.         return $this->redirectToRoute('index');
  157.     }
  158.     
  159.     protected function createTvaForm(Customer $customer, \Doctrine\ORM\EntityManagerInterface $em, \Symfony\Contracts\Translation\TranslatorInterface $translator$from) {
  160.         return $this->createForm(\App\Form\Customer\TvaType::class, $customer,[
  161.             'action' => $this->generateUrl('customer_tva_popup', ['from'=>$from]),
  162.             'method' => 'POST',
  163.             'entity_manager'=>$em,
  164.             'translator'=>$translator
  165.         ]);
  166.     }
  167.     
  168.     /**
  169.      * @Route("/{_locale}/customer/popup/tva", name="customer_tva_popup")
  170.      */
  171.     public function tvaPopup(Request $requestCustomerManager $customerMgr, \Doctrine\ORM\EntityManagerInterface $em, \Symfony\Contracts\Translation\TranslatorInterface $translator)
  172.     {
  173.         $output = [
  174.             'success' => false,
  175.             'message' => ''
  176.         ];
  177.         $from $request->get('from','index');
  178.         $customer $customerMgr->getCustomer();
  179.         if(!empty($customer))
  180.             return $this->redirectToRoute ('customer_account');
  181.         $tvaForm $this->createTvaForm($customer$em$translator$from);
  182.         $customerId $customer->getId();
  183.         if($request->isMethod('POST')){
  184.             $tvaForm->handleRequest($request);
  185.             if($tvaForm->isSubmitted() && $tvaForm->isValid()){
  186.                 try {
  187.                     $customer $tvaForm->getData();
  188.                     if($customer->getId() == $customerId){
  189.                         $em->persist($customer);
  190.                         $em->flush();
  191.                         $output['success'] = true;
  192.                     }else{
  193.                         $output['message'] = "Identification incorrecte.";
  194.                     }
  195.                 } catch (\Exception $ex) {
  196.                     $output['message'] = "Données saisies non valides.";
  197.                 }
  198.             }else{
  199.                 $output['message'] = "Données saisies non valides.";
  200.             }
  201.         }
  202.         return new JsonResponse($output);
  203.     }
  204.     
  205.     /**
  206.      * @Route("/{_locale}/customer/register", name="customer_register")
  207.      */
  208.     public function register(Request $requestCustomerManager $customerMgrSession $session, \Doctrine\ORM\EntityManagerInterface $em, \Symfony\Contracts\Translation\TranslatorInterface $translator)
  209.     {
  210.         $from $request->get('from','customer_account');
  211.         $email $session->get('email','');
  212.         $registerForm $this->createForm(\App\Form\Customer\RegisterType::class,['email'=>$email],[
  213.             'action' => $this->generateUrl('customer_register', ['from'=>$from]),
  214.             'method' => 'POST',
  215.             'entity_manager'=>$em,
  216.             'translator'=>$translator,
  217.             'locale' => $request->getLocale(),
  218.             'attr' => [
  219.                 'novalidate'=>'novalidate'
  220.             ]
  221.         ]);
  222.         if($request->isMethod('POST')){
  223.             $registerForm->handleRequest($request);
  224.             if($registerForm->isValid()){
  225.                 $data $registerForm->getData();
  226.                 $result $customerMgr->register($data$request->getLocale());
  227.                 if($result!==false){
  228.                     $session->getFlashBag()->add('popup'$translator->trans("Votre demande de création de compte a bien été prise en compte. Votre compte sera activé sous 72h. Au-delà de ce délai, si vous rencontrez des problèmes de connexion, nous vous invitons à contacter le service client au +33 (0)2 47 73 38 38, email : infos@vivog.fr."));
  229.                     return $this->redirectToRoute($from);
  230.                 }else{
  231.                     $session->getFlashBag()->add('error'$result);
  232.                 }
  233.             }
  234.         }
  235.         return $this->render('front/customer/register.html.twig',[
  236.             'registerForm' => $registerForm->createView()
  237.         ]);
  238.     }
  239.     
  240.     /**
  241.      * @Route("/{_locale}/customer/password", name="customer_password")
  242.      */
  243.     public function password(Request $requestCustomerManager $customerMgr, \Doctrine\ORM\EntityManagerInterface $emSession $session, \Symfony\Contracts\Translation\TranslatorInterface $translator)
  244.     {
  245.         $from $request->get('from','customer_account');
  246.         $passwordForm $this->createForm(\App\Form\Customer\PasswordRecoveryType::class,null,[
  247.             'action' => $this->generateUrl('customer_password', ['from'=>$from]),
  248.             'method' => 'POST',
  249.             'translator' => $translator,
  250.             'locale' => $request->getLocale()
  251.         ]);
  252.         if($request->isMethod('POST')){
  253.             $passwordForm->handleRequest($request);
  254.             if($passwordForm->isValid()){
  255.                 $data $passwordForm->getData();
  256.                 $result $customerMgr->renewPassword($data['email'], $request->getLocale());
  257.                 if($result !== true){
  258.                     $session->getFlashBag()->add('error'$result);
  259.                 }
  260.                 $session->getFlashBag()->add('notice'$translator->trans('Un nouveau mot de passe a été envoyé à votre adresse email.'));
  261.                 return $this->redirectToRoute('customer_login');
  262.             }
  263.         }
  264.         return $this->render('front/customer/password.html.twig', [
  265.             'passwordForm' => $passwordForm->createView()
  266.         ]);
  267.     }
  268.     
  269.     /**
  270.      * @Route("/{_locale}/customer/password/change", name="customer_password_change")
  271.      */
  272.     public function changePassword(Request $requestCustomerManager $customerMgr, \Doctrine\ORM\EntityManagerInterface $emSession $session, \Symfony\Contracts\Translation\TranslatorInterface $translator)
  273.     {
  274.         $from $request->get('from','customer_account');
  275.         $customer $customerMgr->getCustomer();
  276.         if(empty($customer))
  277.             return $this->redirectToRoute ('customer_login',['from'=>'customer_account']);
  278.         $passwordForm $this->createForm(\App\Form\Customer\PasswordChangeType::class,null,[
  279.             'action' => $this->generateUrl('customer_password_change', ['from'=>$from]),
  280.             'method' => 'POST',
  281.         ]);
  282.         if($request->isMethod('POST')){
  283.             $passwordForm->handleRequest($request);
  284.             if($passwordForm->isValid()){
  285.                 $data $passwordForm->getData();
  286.                 $result $customerMgr->changePassword($customer$data['password'], $data['plainPassword']);
  287.                 if($result===true){
  288.                     $session->getFlashBag()->add('notice'$translator->trans('Votre mot de passe a été mis à jour...'));
  289.                 }else{
  290.                     $session->getFlashBag()->add('error'$result);
  291.                 }
  292.                 return $this->redirectToRoute('customer_password_change');
  293.             }
  294.         }
  295.         return $this->render('front/customer/password-change.html.twig', [
  296.             'customer' => $customer,
  297.             'passwordForm' => $passwordForm->createView()
  298.         ]);
  299.     }
  300.     
  301.     /**
  302.      * @Route("/{_locale}/customer/account", name="customer_account")
  303.      */
  304.     public function account(CustomerManager $customerMgr)
  305.     {
  306.         $customer $customerMgr->getCustomer();
  307.         if(!$customer){
  308.             return $this->redirectToRoute('customer_login',[
  309.                 'from'=>'customer_account'
  310.             ]);
  311.         }
  312.         return $this->render('front/customer/account.html.twig', [
  313.             'customer' => $customer
  314.         ]);
  315.     }
  316.     
  317.     /**
  318.      * @Route("/{_locale}/aj/customer/address", name="customer_address" )
  319.      */
  320.     public function addressUpdate(Request $requestCustomerManager $customerMgr, \Doctrine\ORM\EntityManagerInterface $em, \Symfony\Contracts\Translation\TranslatorInterface $translator)
  321.     {
  322.         $customer $customerMgr->getCustomer();
  323.         if(!$customer){
  324.             return $this->redirectToRoute('customer_login',[
  325.                 'from'=>'customer_account'
  326.             ]);
  327.         }
  328.         $address null;
  329.         $id $request->get('id',0);
  330.         $from $request->get('from',false);
  331.         if($id)
  332.             $address $em->getRepository('App:Address')->find($id);
  333.         if(empty($address)){
  334.             $address = new \App\Entity\Address();
  335.             $france $em->getRepository(\App\Entity\Country::class)->find(73);
  336.             $address->setCountry($france);
  337.         }elseif($address->getCustomer()!=$customer){
  338.             throw new NotFoundHttpException();
  339.         }
  340.         $actionData = ['id'=>$id];
  341.         if(!empty($from)){
  342.             $actionData['from'] = $from;
  343.         }
  344.         $form $this->createForm(\App\Form\Customer\AddressType::class, $address,[
  345.             'action' => $this->generateUrl('customer_address',$actionData),
  346.             'method' => 'POST',
  347.             'entity_manager' => $em,
  348.             'translator' => $translator,
  349.             'attr' => [
  350.                 'id'=>'form-address',
  351.                 'novalidate'=>'novalidate'
  352.             ]
  353.         ]);
  354.         
  355.         if($request->isMethod('POST')){
  356.             $form->handleRequest($request);
  357.             if($form->isValid()){
  358.                 try{
  359.                     $address $form->getData();
  360.                     $address->setCustomer($customer);
  361.                     $em->persist($address);
  362.                     $default $form->get('default')->getData();
  363.                     if(!empty($default)){
  364.                         $customer->setDefaultAddress($address);
  365.                         $em->persist($customer);
  366.                     }
  367.                     $em->flush();
  368.                     return new JsonResponse([
  369.                         'success'=>true,
  370.                         'address'=>$address->toArray(),
  371.                         'redirect'=>empty($from)?false:$this->redirectToRoute ($from)
  372.                     ]);
  373.                 }
  374.                 catch (\Exception $ex) {
  375.                     return new JsonResponse([
  376.                         'success'=>false,
  377.                         'error'=>$ex->getMessage()
  378.                     ]);
  379.                 }
  380.             }
  381.         }     
  382.         
  383.         $content $this->renderView('front/customer/forms/address.html.twig',[
  384.             'addressForm' => $form->createView()
  385.         ]);
  386.         $response = new JsonResponse();
  387.         $response->setContent(json_encode([
  388.             'content' => $content
  389.         ]));
  390.         return $response;
  391.     }
  392.     
  393.     /**
  394.      * @Route("/{_locale}/aj/customer/address/selection", name="customer_address_selection" )
  395.      */
  396.     public function addressSelection(Request $requestCustomerManager $customerMgrEntityManagerInterface $em)
  397.     {
  398.         $type $request->get('type','');
  399.         $customer $customerMgr->getCustomer();
  400.         if(!$customer){
  401.             throw new NotFoundHttpException();
  402.         }
  403.         $addresses $em->getRepository('App:Address')->findByCustomer($customer);
  404.         $content $this->renderView('front/customer/blocks/address-selection.html.twig',[
  405.             'addresses' => $addresses,
  406.             'type' => $type
  407.         ]);
  408.         $response = new JsonResponse();
  409.         $response->setContent(json_encode([
  410.             'content' => $content
  411.         ]));
  412.         return $response;
  413.     }
  414.     
  415.     /**
  416.      * @Route("/{_locale}/aj/customer/address/delete", name="customer_address_delete" )
  417.      */
  418.     public function deleteAddress(Request $requestCustomerManager $customerMgrEntityManagerInterface $em, \Symfony\Contracts\Translation\TranslatorInterface $translator)
  419.     {
  420.         $id $request->get('id','');
  421.         $customer $customerMgr->getCustomer();
  422.         if(!$customer){
  423.             throw new NotFoundHttpException();
  424.         }
  425.         $address $em->getRepository('App:Address')->findByCustomer($customer);
  426.         
  427.         try{
  428.             $address $em->getRepository('App:Address')->find($id);
  429.             if($address){
  430.                 if($address->getId() == $customer->getDefaultAddressId())
  431.                     throw new \Exception($translator->trans('Impossible de supprimer votre adresse principale.'));
  432.                 $em->remove($address);
  433.                 $em->flush();
  434.             }else{
  435.                 throw new \Exception($translator->trans('Adresse inconnue.'));
  436.             }
  437.             return new JsonResponse([
  438.                 'success'=>true,
  439.                 'address'=>$address->toArray()
  440.             ]);
  441.         }
  442.         catch (\Exception $ex) {
  443.             return new JsonResponse([
  444.                 'success'=>false,
  445.                 'error'=>$ex->getMessage()
  446.             ]);
  447.         }
  448.         $response = new JsonResponse();
  449.         $response->setContent(json_encode([
  450.             'success'=>false,
  451.             'error'=>''
  452.         ]));
  453.         return $response;
  454.     }
  455.     
  456.     /**
  457.      * @Route("/{_locale}/customer/information", name="customer_information")
  458.      */
  459.     public function information(Request $request, \Symfony\Component\HttpFoundation\Session\SessionInterface $sessionCustomerManager $customerMgrEntityManagerInterface $em, \Symfony\Contracts\Translation\TranslatorInterface $translator)
  460.     {
  461.         $customer $customerMgr->getCustomer();
  462.         if(!$customer){
  463.             return $this->redirectToRoute('customer_login',[
  464.                 'from'=>'customer_history'
  465.             ]);
  466.         }
  467.         $form $this->createForm(\App\Form\Customer\InformationType::class, $customer, [
  468.             'method' => 'POST',
  469.             'attr' => [
  470.                 'novalidate' => 'novalidate',
  471.                 'class' => 'customer-info'
  472.             ],
  473.             'translator' => $translator
  474.         ]);
  475.         if($request->isMethod('POST')){
  476.             $form->handleRequest($request);
  477.             if($form->isValid()){
  478.                 $customer $form->getData();
  479.                 try{
  480.                     $customer->setAccountUpdate(new \DateTime);
  481.                     $em->persist($customer);
  482.                     $em->flush();
  483.                     $session->getFlashBag()->add('notice',$translator->trans('Vos informations ont été enregistrées.'));
  484.                     return $this->redirectToRoute('customer_information');
  485.                 }
  486.                 catch (\Exception $ex) {
  487.                     $session->getFlashBag()->add('error',$translator->trans('Une erreur est survenue.'));
  488.                 }
  489.             } else {
  490.                 $session->getFlashBag()->add('error',$translator->trans('Erreur présente dans le formulaire.'));
  491.             }
  492.         }
  493.         return $this->render('front/customer/informations.html.twig', [
  494.             'customer' => $customer,
  495.             'form' => $form->createView()
  496.         ]);
  497.     }
  498.     
  499.     /**
  500.      * @Route("/{_locale}/customer/history", name="customer_history")
  501.      */
  502.     public function history(CustomerManager $customerMgrEntityManagerInterface $em)
  503.     {
  504.         $customer $customerMgr->getCustomer();
  505.         if(!$customer){
  506.             return $this->redirectToRoute('customer_login',[
  507.                 'from'=>'customer_history'
  508.             ]);
  509.         }
  510.         $orders $em->getRepository('App:Order')->history($customer);
  511.         return $this->render('front/customer/history.html.twig', [
  512.             'customer' => $customer,
  513.             'orders' => $orders
  514.         ]);
  515.     }
  516.     
  517.     /**
  518.      * @Route("/{_locale}/customer/addresses", name="customer_addresses")
  519.      */
  520.     public function adresses(CustomerManager $customerMgrEntityManagerInterface $em)
  521.     {
  522.         $customer $customerMgr->getCustomer();
  523.         if(!$customer){
  524.             return $this->redirectToRoute('customer_login',[
  525.                 'from'=>'customer_addresses'
  526.             ]);
  527.         }
  528.         $addresses $em->getRepository('App:Address')->findByCustomer($customer);
  529.         return $this->render('front/customer/addresses.html.twig', [
  530.             'customer' => $customer,
  531.             'addresses' => $addresses
  532.         ]);
  533.     }
  534.     
  535.     /**
  536.      * @Route("/{_locale}/json/customer/invoiceType/{cid}/{token}/{type}", name="json_customer_invoice_type", requirements={"cid"="\d+","type":"0|1","token":".+"})
  537.      */
  538.     public function invoiceType(Request $request$cid$token$type)
  539.     {
  540.         $em $this->getDoctrine()->getManager();
  541.         $output = ['success' => false'message'=>''];
  542.         if($request->isMethod('POST')){
  543.             $customer null;
  544.             if(md5('LKLSDF456ERF'.$cid) == $token){
  545.                 $customer $em->getRepository('App:Customer')->find($cid);
  546.             }
  547.             if(empty($customer))
  548.                 throw new NotFoundHttpException ();
  549.             try{
  550.                 $customer->setInvoiceType($type);
  551.                 $em->persist($customer);
  552.                 $em->flush();
  553.                 $output['success'] = true;
  554.             }
  555.             catch (\Exception $ex) {
  556.                 $output['message'] = $ex->getMessage();
  557.             }
  558.         }
  559.         $response = new JsonResponse($output);
  560.         if(!empty($_SERVER['HTTP_ORIGIN'])){
  561.             $http_origin $_SERVER['HTTP_ORIGIN'];
  562.             if (in_array($http_origin,["https://test.dogcat.com","https://www.dogcat.com","https://v2.dogcat.com","https://v2-test.dogcat.com"]))
  563.             {  
  564.                 $response->headers->set("Access-Control-Allow-Origin",$http_origin);
  565.             }
  566.         }  
  567.         return $response;
  568.     }
  569.     
  570.     
  571. }