src/Controller/WebController.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\App;
  4. use App\Entity\AppSharing;
  5. use App\Entity\Flow;
  6. use App\Entity\Page;
  7. use App\Form\FlowFormType;
  8. use App\Service\AlgorithmService;
  9. use App\Service\FlowService;
  10. use App\Service\PageGeneratorService;
  11. use App\Service\RestGeneratorService;
  12. use DeviceDetector\DeviceDetector;
  13. use DeviceDetector\Parser\Client\Browser;
  14. use DeviceDetector\Parser\OperatingSystem;
  15. use Doctrine\Persistence\ManagerRegistry;
  16. use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpKernel\Profiler\Profiler;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. use Symfony\Component\HttpKernel\KernelInterface;
  21. use Twig\Environment;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. class WebController extends EasyAdminController  {
  24.     public function __construct(ManagerRegistry $managerRegistryPageGeneratorService $pageGeneratorServiceTranslatorInterface $translatorRestGeneratorService $restGeneratorService) {
  25.         $this->doctrine $managerRegistry;
  26.         $this->pageGeneratorService $pageGeneratorService;
  27.         $this->translator $translator;
  28.         $this->restGeneratorService $restGeneratorService;
  29.     }
  30.     public function index(Request $requestFlowService $flowServiceAlgorithmService $algorithmService )
  31.     {
  32.         $em $this->doctrine->getManager();
  33.         $form $this->createFormFlowFormType::class, null, array('custom'=>) );
  34.         $form->handleRequest$request );
  35.         if ($form->isSubmitted()) {
  36.             $fuuid  $form['fuuid']->getData();
  37.             $query_input_data $request->query->all();
  38.             $post_input_data $request->request->all();
  39.             //$input_data = array('query'=>$query_input_data,'form'=>$post_input_data['flow_form'] );
  40.             $input_data array_merge($post_input_data['flow_form'], $query_input_data);
  41.             $Flow $em->getRepository(Flow::class)->findOneBy(['Fuuid'=>$fuuid]);
  42.             $Flow $flowService->executeFlow($Flow$input_data,'pl');
  43.             return $this->render('website/index.html.twig', [
  44.                 'form' => $form->createView(),
  45.                 'fuuid' => $fuuid,
  46.             ]);
  47.         } else {
  48.             return $this->render('website/index.html.twig', [
  49.                 'form' => $form->createView(),
  50.                 'fuuid'=>null
  51.             ]);
  52.         }
  53.     }
  54.     /**
  55.      * @Route("/webapp/{customer}/{appid}", name="share_webapp")
  56.      */
  57.     public function webappRequest $request$customer=''$appid='') {
  58.         $em $this->doctrine->getManager();
  59.         $basePath $request->getSchemeAndHttpHost();
  60.         $App $em->getRepository(App::class)->find($appid);
  61.         $Customer $App->getCustomer();
  62.         $customerUuid $Customer->getUuid();
  63.         $customerSlug $Customer->getSlug();
  64.         $appId $App->getId();
  65.     
  66.         $appDirectoryPath "$basePath/customer/{$customerSlug}-{$customerUuid}/apps/{$appId}/web/index.html";
  67.         return $this->render('website/webapp.html.twig',
  68.             [
  69.             'locale'=>'pl',
  70.             'path'=>$appDirectoryPath
  71.         ]);
  72.     }
  73.     /**
  74.      * @Route("/r/{appid}/{code}", name="url_redirect")
  75.      */
  76.     public function url_redirect(Request $request$code=''$appid='') {
  77.         $em $this->doctrine->getManager();
  78.         $data  $request->query->get'd' );
  79.         $pageid  $request->query->get'pageid' ); // landing page page id
  80.         $p  $request->query->get'p' ); // pageId directly in link
  81.         // User changes password using form.
  82.         $actionUrl  $request->request->get'applnkact' );
  83.         $emailUrl  $request->request->get'email' );
  84.         $passwordUrl  $request->request->get'new_password' );
  85.         $password2Url  $request->request->get'password2' );
  86.         $codeUrl  $request->request->get'prc' );
  87.         $codeLength strlen($code);
  88.         if ($codeLength == 4) {
  89.             $AppSharing $em->getRepository(AppSharing::class)->findOneBy(array('Code' => $code'App'=>$appid));
  90.             $linkCode $AppSharing->getCode();
  91.             $pageId $AppSharing->getPage()->getId();
  92.         } elseif ($codeLength == 8) {
  93.             $parentCode substr($code04);
  94.             $linkCode substr($code44);
  95.             $AppSharing $em->getRepository(AppSharing::class)->findOneBy(array('Code' => $parentCode'App'=>$appid));
  96.             $appPagesArray $AppSharing->getAppPages();
  97.             $pageId $this->pageGeneratorService->findChildAppPage($appPagesArray$linkCode);
  98.         }
  99.         if (empty($AppSharing)) {
  100.             return $this->render('website/redirect.html.twig',
  101.                 ['childpages'=>'''appid'=>$appid'code' => '''data' => '''title' => 'redirect_code_not_found_title''body' => 'redirect_code_not_found_full_message''link' => '''qr' => '''osFamily' => '''browser' => '''showAppstores' =>false'urlAppStore' => '''urlGooglePlay' => '''urlHuaweiAppGallery' => '']);
  102.         }
  103.         $App $AppSharing->getApp();
  104.         $showLink $AppSharing->getShowLink();
  105.         $showQr $AppSharing->getShowQr();
  106.         $showAppstores $AppSharing->getShowAppStores();
  107.         $webUrl $AppSharing->getWebUrl();
  108.         $appSettings $AppSharing->getApp()->getSettings();
  109.         $type $AppSharing->getType();
  110.         $redirectMobile $AppSharing->getRedirectMobile();
  111.         $redirectWeb $AppSharing->getRedirectWeb();
  112.         $pages $AppSharing->getPages();
  113.         $childpages = array();
  114.         $appIcon $App->getIcon();
  115.         $clientLocale strtolower(str_split($_SERVER['HTTP_ACCEPT_LANGUAGE'], 2)[0]);
  116.         $lang $clientLocale// todo - what if client locale is different than any in db ?
  117.         if ($pageid 0) { // pageid is used in the mobile's page menu to access individual pages of the landing page
  118.             $Page $em->getRepository(Page::class)->findOneBy(array('id'=>$pageid'App'=>$App));
  119.         }
  120.         foreach ($pages as $page) {
  121.             $childId $page['Child'];
  122.             $childPage $em->getRepository(Page::class)->find($childId);
  123.             $childpages[$childId] = $childPage->translate($clientLocale)->getName();
  124.         }
  125.         $this->translator->setLocale($clientLocale);
  126.         if (!empty($Page)) { // open a page with give pageid
  127.             $pageTitle $Page->translate($clientLocale)->getName();
  128.             $pageBody $Page->translate($clientLocale)->getBody();
  129.             return $this->render('website/redirect.html.twig',
  130.                 ['childpages'=>$childpages,
  131.                     'appid'=>$appid,
  132.                     'code' => $code,
  133.                     'data' => $data,
  134.                     'title' => $pageTitle,
  135.                     'appIcon' => $appIcon,
  136.                     'body' => $pageBody,
  137.                     'link' => '',
  138.                     'qr' => '',
  139.                     'osFamily' => '',
  140.                     'browser' => '',
  141.                     'showAppstores' => false,
  142.                     'urlAppStore' => '',
  143.                     'urlGooglePlay' => '',
  144.                     'urlHuaweiAppGallery' => '',
  145.                     'locale'=>'pl']);
  146.         } else {
  147.             $userAgent $_SERVER['HTTP_USER_AGENT'];
  148.             $dd = new DeviceDetector($userAgent);
  149.             $dd->parse();
  150.             $osFamily OperatingSystem::getOsFamily($dd->getOs('name'));
  151.             $browserFamily Browser::getBrowserFamily($dd->getClient('name'));
  152.             $isSmartphone $dd->isSmartphone();
  153.             $pageTitle $AppSharing->translate($clientLocale)->getName();
  154.             $pageBody $AppSharing->translate($clientLocale)->getBody();
  155.             $urlAppStore = (isset($appSettings['urlAppStore'])) ? $appSettings['urlAppStore'] : '';
  156.             $urlGooglePlay = (isset($appSettings['urlGooglePlay'])) ? $appSettings['urlGooglePlay'] : '';
  157.             $urlHuaweiAppGallery = (isset($appSettings['urlHuaweiAppGallery'])) ? $appSettings['urlHuaweiAppGallery'] : '';
  158.             $appTranslations $App->translate($lang)->getTranslationStrings();
  159.             if (!empty($p)) {
  160.                 $link $webUrl '?page_id=' $p;
  161.             } else {
  162.                 $link $webUrl '?page_id=' $this->pageGeneratorService->buildPageId($pageId11null);
  163.             }
  164.             if ($type == "db") {
  165.                 $link .= '?c=' $code;
  166.             } elseif ($type == "qr") {
  167.                 $link .= '?d=' $data;
  168.             }
  169.             if (($dd->isSmartphone()) && ($redirectMobile)) {
  170.                 return $this->redirect($link);
  171.             } elseif ($redirectWeb) {
  172.                 return $this->redirect($link);
  173.             }
  174.             if (!$showLink) {
  175.                 $link '';
  176.             }
  177.             if (($showQr) && (!$isSmartphone)) {
  178.                 $appUserFilesPath $this->pageGeneratorService->buildAppFilesPublicUrl($App);
  179.                 $qr $appUserFilesPath.'/qr/'.$linkCode.'.png';
  180.             } else {
  181.                 $qr '';
  182.             }
  183.             $externalDataArray json_decode(base64_decode(strtr($data'._-','+/=')), TRUE);
  184.             $inputData $this->restGeneratorService->parseExternalData($externalDataArray);
  185.             $action =  (isset($inputData['applnkact'])) ? $inputData['applnkact'] : null;
  186.             $prc =  (isset($inputData['prc'])) ? $inputData['prc'] : '';
  187.             $email =  (isset($inputData['email'])) ? $inputData['email'] : '';
  188.             if ($actionUrl == 'changepwd') {
  189.                 $data = array('email'=>$emailUrl,'applnkact'=>'resetpwd','prc'=>$codeUrl'password'=>$passwordUrl'password2'=>$password2Url);
  190.                 $Patient $this->restGeneratorService->verifyPasswordResetCode($data$App);
  191.                 if (!empty($Patient)) {
  192.                     $errors $this->restGeneratorService->checkPassword($passwordUrl$password2Url);
  193.                     if (empty($errors)) {
  194.                         $Patient->setPlainPassword($passwordUrl);
  195.                         $this->restGeneratorService->encodePassword($Patient);
  196.                         //$em->persist($Patient);
  197.                         //$em->flush();
  198.                         $message 'password changed';
  199.                         $status 'success';
  200.                         $pageBody '<div class="alert alert-info">'.$message.'</div>';
  201.                     } else {
  202.                         $message implode(' '$errors);
  203.                         $pageBody '<div class="alert alert-danger">'.$message.'</div>';
  204.                     }
  205.                 }
  206.             } elseif ($action == 'veremail') {
  207.                 $emailVerified $this->restGeneratorService->verifyEmailCode($inputData$App);
  208.                 if ($emailVerified) {
  209.                     $message $this->restGeneratorService->getAppTranslation($appTranslations'account_email_verified_message'); // create verification success message
  210.                     $pageBody '<div class="alert alert-info">'.$message.'</div>';
  211.                 } else {
  212.                     $message $this->restGeneratorService->getAppTranslation($appTranslations'form_validation_incorrect_form_data'); // create verification failure message
  213.                     $pageBody '<div class="alert alert-danger">'.$message.'</div>';
  214.                 }
  215.             } elseif ($action == 'resetpwd') {
  216.                 $label $this->restGeneratorService->getAppTranslation($appTranslations'password_reset_button');
  217.                 $form $this->restGeneratorService->buildPasswordChangeForm($inputData$pageId$App$lang);
  218.                 $form[] = array('variableShortcode'=>'email''variableName'=>'''variableSuffix'=>'','variableDescription'=>'''required'=>true'variableType'=>'hidden''inputFieldSettings'=>[], 'value'=>$email);
  219.                 $form[] = array('variableShortcode'=>'prc''variableName'=>'''variableSuffix'=>'','variableDescription'=>'''required'=>true'variableType'=>'hidden''inputFieldSettings'=>[], 'value'=>$prc);
  220.                 $form[] = array('variableShortcode'=>'applnkact''variableName'=>'''variableSuffix'=>'','variableDescription'=>'''required'=>true'variableType'=>'hidden''inputFieldSettings'=>[], 'value'=>'changepwd');
  221.                 $form[] = array('variableShortcode'=>'submit''variableName'=>$label 'variableSuffix'=>'','variableDescription'=>'''required'=>true'variableType'=>'button''inputFieldSettings'=>['buttonAction'=>'submit'], 'value'=>'');
  222.                 $pageBody $this->pageGeneratorService->buildAppFormHtml('post''''password_reset'$form);
  223.             }
  224.             return $this->render('website/redirect.html.twig',
  225.                 ['childpages'=>$childpages,
  226.                     'appid'=>$appid,
  227.                     'code' => $code,
  228.                     'data' => $data,
  229.                     'title' => $pageTitle,
  230.                     'appIcon' => $appIcon,
  231.                     'body' => $pageBody,
  232.                     'link' => $link,
  233.                     'qr' => $qr,
  234.                     'osFamily' => $osFamily,
  235.                     'browser' => $browserFamily,
  236.                     'showAppstores' => $showAppstores,
  237.                     'urlAppStore' => $urlAppStore,
  238.                     'urlGooglePlay' => $urlGooglePlay,
  239.                     'urlHuaweiAppGallery' => $urlHuaweiAppGallery
  240.                 ]);
  241.         }
  242.     }
  243. }