src/Controller/UserController.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class UserController extends AbstractController {
  9.     /**
  10.      * @Route("/profile", name="user_profile")
  11.      * @IsGranted("ROLE_USER")
  12.      * @return Response
  13.      */
  14.     public function userProfile(): Response {
  15.         return $this->render("profile.html.twig");
  16.     }
  17.     /**
  18.      * @Route("/transfers", name="user_transfers")
  19.      * @IsGranted("ROLE_USER")
  20.      * @return Response
  21.      */
  22.     public function userTransfers(): Response {
  23.         return $this->render("transfers.html.twig");
  24.     }
  25.     /**
  26.      * @Route("/documents", name="user_documents")
  27.      * @IsGranted("ROLE_USER")
  28.      * @return Response
  29.      */
  30.     public function userDocuments(): Response {
  31.         return $this->render("documents.html.twig");
  32.     }
  33.     /**
  34.      * @Route("/domains", name="user_domains")
  35.      * @IsGranted("ROLE_USER")
  36.      * @return Response
  37.      */
  38.     public function userDomains(): Response {
  39.         return $this->render("domains.html.twig");
  40.     }
  41.     /**
  42.      * @Route("/orders", name="user_orders")
  43.      * @IsGranted("ROLE_USER")
  44.      * @return Response
  45.      */
  46.     public function userOrders(): Response {
  47.         return $this->render("orders.html.twig");
  48.     }
  49.     /**
  50.      * Zasób wyświetla formularz rozpoczynający procedurę resetu hasła.
  51.      * @Route ("/reset1", name="reset-password-stage-1")
  52.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  53.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  54.      * @param \App\Service\Cezar $C
  55.      * @return Response
  56.      */
  57.     public function resetPasswordStage1 (\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie, \App\Service\Cezar $C): Response {
  58.         if ($zadanie->getMethod() == "POST") {
  59.             $email $zadanie->get ("email"null);
  60.             if ($email) {
  61.                 if (!filter_var($emailFILTER_VALIDATE_EMAIL)) {
  62.                     return $this->render ("reset1.html.twig", [
  63.                         "alerts" => [ "Podany adres e-mail nie wygląda prawidlowo." ],
  64.                         "email" => $email
  65.                     ]);                    
  66.                 }
  67.             } else {
  68.                 return $this->render ("reset1.html.twig", [
  69.                     "alerts" => [ "Proszę podać adres e-mail." ],
  70.                     "email" => $email
  71.                 ]);
  72.             }
  73.             $U $EM->getRepository (\App\Entity\Klient::class)->findOneBy ([ "email" => $email]);
  74.             if ($U) {
  75.                 
  76.                 // Create the Transport
  77.                 $transport = new \Swift_SmtpTransport(
  78.                     $EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, serwer""mail.ndc.pl"),
  79.                     intval ($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, port""465")),
  80.                     intval ($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, szyfrowanie""TLS"))
  81.                 );
  82.                 $transport->setUsername($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, skrzynka""info@ndc.pl"));
  83.                 $transport->setPassword($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, hasło"""));
  84.                 // Create the Mailer using your created Transport
  85.                 $mailer = new \Swift_Mailer($transport);
  86.                 // Create a message
  87.                 $message = new \Swift_Message($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Temat maila resetującego hasło""RESET hasła"));
  88.                 $message->setFrom([
  89.                     $EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, adres""info@ndc.pl") => $EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, nazwa""InforPol NET")
  90.                 ]);
  91.                 $message->setTo([$U->getEmail() => $U->getNazwa()]);
  92.                 $timeout date ("Y-m-d H:i:s"time() + intval ($EM->getRepository(\App\Entity\Konfiguracja::class)->peek ("Czas na reset hasła [s]""900")));
  93.                 $message->setBody(
  94.                     $this->renderView("email/reset_hasla.html.twig", [
  95.                         "linkId" => $C->match($timeout " " strval($U->getId()) . " " md5(strval($U->getId()))),
  96.                         "timeout" => $timeout
  97.                     ]),
  98.                     'text/html'
  99.                 );
  100.                 try {
  101.                     $result $mailer->send($message);
  102.                 } catch (\Exception $e) {                    
  103.                     $error $e->getMessage();
  104.                 }
  105.                 
  106.             }
  107.             if (isset ($error)) {
  108.                 return $this->render ("reset2.html.twig", [
  109.                     "email" => $email,
  110.                     "timeout" => $timeout,
  111.                     "error" => $error
  112.                     ]);
  113.             } else {
  114.                 return $this->render ("reset2.html.twig", [
  115.                     "email" => $email,
  116.                     "timeout" => $timeout
  117.                     ]);                
  118.             }
  119.         }
  120.         return $this->render ("reset1.html.twig");
  121.     }
  122.     
  123.     /**
  124.      * Zasób obsługuje link do formularza ustawiania nowego hasła     
  125.      * @Route ("/reset2/{link}", name="set_new_pass")
  126.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  127.      * @param \App\Service\Cezar $C
  128.      * @param \App\Service\PasswordVerify $PV
  129.      * @param string $link
  130.      * @return Response
  131.      */
  132.     public function setNewPasswordLink (\Doctrine\ORM\EntityManagerInterface $EM, \App\Service\Cezar $C, \App\Service\PasswordVerify $PVstring $link): Response {
  133.         $links explode (" "$C->demath($link));
  134.         if (count ($links) != 4) {
  135.             return $this->render ("reset-bad-link.html.twig", [ "link" => $link ], new Response (""404));
  136.             //Nieprawidłowy link
  137.         } else {
  138.             if (md5($links [2]) != $links [3]) {
  139.                 //Nieprawidłowy link
  140.                 return $this->render("reset-bad-link.html.twig", [ "link" => $link ], new Response (""404));
  141.             } else {
  142.                 $czas strtotime ($links [0] . " " $links [1]);
  143.                 if ($czas time()) {
  144.                     //Timeout
  145.                     return $this->render("reset-expired-link.html.twig", [ "link" => $link"timeout" => $links [0] . " " $links [1] ]);
  146.                 } else {
  147.                     //RESET OK     
  148.                     $U $EM->getRepository(\App\Entity\Klient::class)->find (intval ($links [2]));
  149.                     if ($U) {
  150.                         return $this->redirectToRoute("set-new-pass-form", [ "link" => $link ]);
  151.                     } else {
  152.                         return $this->render("reset-expired-link.html.twig", [ "link" => $link"timeout" => $links [0] . " " $links [1] ]);
  153.                     }
  154.                 }
  155.             }
  156.         }
  157.     }
  158.     
  159.     /**
  160.      * Zasób obsługuje formularz ustawiania hasła
  161.      * @Route("/set-new-pass/{link}", name="set-new-pass-form")
  162.      * @param \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $UPHI
  163.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  164.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  165.      * @param \App\Service\Cezar $C
  166.      * @param \App\Service\PasswordVerify $PV
  167.      * @param string $link
  168.      * @return Response
  169.      */
  170.     public function setNewPassword (\Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $UPHI, \Symfony\Component\HttpFoundation\Request $zadanie, \Doctrine\ORM\EntityManagerInterface $EM, \App\Service\Cezar $C, \App\Service\PasswordVerify $PVstring $link): Response {
  171.         $links explode (" "$C->demath($link));
  172.         $U $EM->getRepository(\App\Entity\Klient::class)->find (intval ($links [2]));
  173.         if ($zadanie->getMethod() == "POST") {
  174.             $error "";
  175.             $pass = [ => $zadanie->get ("pass1"""), => $zadanie->get ("pass2""") ];
  176.             if ($pass [1] != $pass [2]) {
  177.                 $error .= "Podane hasła są różne.\n";
  178.             }
  179.             if (($pass [1] == "") || ($pass [2] == "")) {
  180.                 $error .= "Hasło nie może być puste.\n";
  181.             }
  182.             if (!$PV->check($pass [1], $EM->getRepository(\App\Entity\Konfiguracja::class))) {
  183.                 $error .= "Hasło jest niezgodne z podanymi zasadami.\n";
  184.             }
  185.             if ($error != "") {
  186.                 $error nl2br(trim ($error));
  187.                 return $this->render ("reset-2.html.twig", [ "link" => $link"user" => $U"pass_help" => $PV->helper($EM->getRepository(\App\Entity\Konfiguracja::class)), "error" => $error ]);
  188.             } else {
  189.                 $EM->persist ($U);
  190.                 $U->setPassword($UPHI->hashPassword($U$pass [1]));
  191.                 $EM->flush ();
  192.                 return $this->render ("reset-success.html.twig", [ "user" => $U ]);
  193.             }
  194.         }
  195.         return $this->render ("reset-2.html.twig", [ "link" => $link"user" => $U"pass_help" => $PV->helper($EM->getRepository(\App\Entity\Konfiguracja::class)) ]);
  196.     }
  197.     
  198.     /**
  199.      * Zasób generuje formularz rejestracyjny
  200.      * @Route("registration-form", name="registration-form", methods={"GET"})
  201.      * @param \App\Repository\KonfiguracjaRepository $KREPO
  202.      * @param \App\Repository\SlownikRodzajKlientaRepository $SRKRepo
  203.      * @param \App\Repository\SlownikKrajISORepository $SKIRepo
  204.      * @param \App\Service\PasswordVerify $PASSV
  205.      * @return Response
  206.      */
  207.     public function registrationForm(\App\Repository\KonfiguracjaRepository $KREPO, \App\Repository\SlownikRodzajKlientaRepository $SRKRepo, \App\Repository\SlownikKrajISORepository $SKIRepo, \App\Service\PasswordVerify $PASSV): Response {
  208.         return $this->render("registration_form.html.twig", [
  209.                     "rodzaje_klientow" => $SRKRepo->findBy([], ["nazwa" => "asc"]),
  210.                     "kraje" => $SKIRepo->findBy([], ["nazwa" => "asc"]),
  211.                     "pass_help" => nl2br($PASSV->helper($KREPO))
  212.         ]);
  213.     }
  214.     /**
  215.      * Funkcja sprawdza poprawność wypełnienia pól formularza rejestracyjnego
  216.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  217.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  218.      * @param \App\Service\phoneVerify $PHONEV
  219.      * @param \App\Service\NIPVerify $NV
  220.      * @param \App\Service\PESELVerify $PV
  221.      * @param \App\Service\PasswordVerify $PASV
  222.      * @return array
  223.      */
  224.     public function checkFieldsInRegistrationForm(\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie, \App\Service\phoneVerify $PHONEV, \App\Service\NIPVerify $NV, \App\Service\PESELVerify $PV, \App\Service\PasswordVerify $PASV): Array {
  225.         $wynik = ["items" => [], "alerts" => []];
  226.         $person false;
  227.         $company false;
  228.         $rodzaje_klientow $EM->getRepository(\App\Entity\SlownikRodzajKlienta::class)->findAll();
  229.         $rodzaj_klienta null;
  230.         foreach ($rodzaje_klientow as $rk) {
  231.             if (strtolower($zadanie->get("rodzaj_klienta_" $rk->getId())) == "true") {
  232.                 $rodzaj_klienta $rk;
  233.                 break;
  234.             }
  235.         }
  236.         $wynik ['input'] = [];
  237.         $wynik ['input']['rodzaj_klienta'] = $rodzaj_klienta;
  238.         $wynik ['input']["login"] = trim($zadanie->get("login"""));
  239.         $wynik ['input']["pass1"] = trim($zadanie->get("pass1"""));
  240.         $wynik ['input']["pass2"] = trim($zadanie->get("pass2"""));
  241.         $wynik ['input']["miasto"] = trim($zadanie->get("miasto"""));
  242.         $wynik ['input']["kod_pocztowy"] = trim($zadanie->get("kod_pocztowy"""));
  243.         $wynik ['input']["ulica"] = trim($zadanie->get("ulica"""));
  244.         $wynik ['input']["kraj"] = trim($zadanie->get("kraj"""));
  245.         $wynik ['input']['adres_koresp'] = (strtolower(trim($zadanie->get("adres_koresp"""))) == "true");
  246.         $wynik ['input']["telefon"] = trim($zadanie->get("telefon"""));
  247.         $wynik ['input']["telefon_komorkowy"] = trim($zadanie->get("telefon_komorkowy"""));
  248.         $wynik ['input']["email"] = trim($zadanie->get("email"""));
  249.         if ($rodzaj_klienta) {
  250.             if (strtolower($rodzaj_klienta->getNazwa()) == "osoba prywatna") {
  251.                 $wynik ['input']["imie_i_nazwisko"] = trim($zadanie->get("imie_i_nazwisko"""));
  252.                 $wynik ['input']['whois'] = (strtolower(trim($zadanie->get("whois"""))) == "true");
  253.                 $wynik ['input']["pesel"] = trim($zadanie->get("pesel"""));
  254.             } elseif (strtolower($rodzaj_klienta->getNazwa()) == "firma") {
  255.                 $wynik ['input']["nip"] = trim($zadanie->get("nip"""));
  256.                 $wynik ['input']["nazwa"] = trim($zadanie->get("nazwa"""));
  257.                 $wynik ['input']["osoba_kontaktowa"] = trim($zadanie->get("osoba_kontaktowa"""));
  258.             }
  259.         }
  260.         if ($wynik ['input']['adres_koresp']) {
  261.             $wynik ['input']["kores_miasto"] = trim($zadanie->get("kores_miasto"""));
  262.             $wynik ['input']["kores_kod_pocztowy"] = trim($zadanie->get("kores_kod_pocztowy"""));
  263.             $wynik ['input']["kores_ulica"] = trim($zadanie->get("kores_ulica"""));
  264.             $wynik ['input']["kores_kraj"] = trim($zadanie->get("kores_kraj"""));
  265.         }
  266.         //Sprawdzanie poprawności danych wejściowych
  267.         if ($wynik ['input']["login"] == "") {
  268.             $wynik ['items'][] = "login";
  269.             $wynik ['alerts'][] = "Login nie może być pusty.";
  270.         } else {
  271.             $test $EM->getRepository(\App\Entity\Klient::class)->findOneBy(["login" => $wynik ['input']['login']]);
  272.             if ($test) {
  273.                 if (!$test->isCzyAktywowany()) {
  274.                     if ((time () - $test->getCrDate()->getTimestamp()) > intval ($EM->getRepository(\App\Entity\Konfiguracja::class)->peek ("Czas na aktywację konta [s]""900"))) {
  275.                         $EM->remove($test);
  276.                         $EM->flush();
  277.                     } else {
  278.                         $wynik ['items'][] = "login";
  279.                         $wynik ['alerts'][] = "Podany login jest już zajęty.";                        
  280.                     }
  281.                 } else {
  282.                     $wynik ['items'][] = "login";
  283.                     $wynik ['alerts'][] = "Podany login jest już zajęty.";
  284.                 }
  285.             }
  286.         }
  287.         if ($wynik ['input']['pass1'] != $wynik ['input']['pass2']) {
  288.             $wynik ['items'][] = "pass1";
  289.             $wynik ['items'][] = "pass2";
  290.             $wynik ['alerts'][] = "podane hasla są różne.";
  291.         } else {
  292.             if ($wynik ['input']['pass1'] == "") {
  293.                 $wynik ['items'][] = "pass1";
  294.                 $wynik ['items'][] = "pass2";
  295.                 $wynik ['alerts'][] = "Hasło nie może być puste.";
  296.             } else {
  297.                 if (!$PASV->check($wynik ['input']['pass1'], $EM->getRepository(\App\Entity\Konfiguracja::class))) {
  298.                     $wynik ['items'][] = "pass1";
  299.                     $wynik ['items'][] = "pass2";
  300.                     $wynik ['alerts'][] = "Hasło nie zgodne z regułami.";
  301.                 }
  302.             }
  303.         }
  304.         if ($wynik ['input']["miasto"] == "") {
  305.             $wynik ['items'][] = "miasto";
  306.             $wynik ['alerts'][] = "Nazwa miejscowości nie może być pusta.";
  307.         }
  308.         if ($wynik ['input']["kod_pocztowy"] == "") {
  309.             $wynik ['items'][] = "kod_pocztowy";
  310.             $wynik ['alerts'][] = "kod pocztowy nie może być pusty.";
  311.         }
  312.         if ($wynik ['input']["ulica"] == "") {
  313.             $wynik ['items'][] = "ulica";
  314.             $wynik ['alerts'][] = "Nazwa ulicy nie może być pusta.";
  315.         }
  316.         if ($wynik ['input']['adres_koresp']) {
  317.             if ($wynik ['input']["kores_miasto"] == "") {
  318.                 $wynik ['items'][] = "kores_miasto";
  319.                 $wynik ['alerts'][] = "Nazwa miejscowości adresu korespondencyjnego nie może być pusta.";
  320.             }
  321.             if ($wynik ['input']["kores_kod_pocztowy"] == "") {
  322.                 $wynik ['items'][] = "kores_kod_pocztowy";
  323.                 $wynik ['alerts'][] = "kod pocztowy adresu korespondencyjnego nie może być pusty.";
  324.             }
  325.             if ($wynik ['input']["kores_ulica"] == "") {
  326.                 $wynik ['items'][] = "kores_ulica";
  327.                 $wynik ['alerts'][] = "Nazwa ulicy adresu korespondencyjnego nie może być pusta.";
  328.             }
  329.         }
  330.         if (($wynik ['input']['telefon'] == "") && ($wynik ['input']['telefon_komorkowy'] == "")) {
  331.             $wynik ['items'][] = "telefon";
  332.             $wynik ['items'][] = "telefon_komorkowy";
  333.             $wynik ['alerts'][] = "Proszę podac przynajmniej jeden numer telefonu.";
  334.         } else {
  335.             if ($wynik ['input']['telefon'] != "") {
  336.                 if (!$PHONEV->check($wynik ['input']['telefon'])) {
  337.                     $wynik ['items'][] = 'mask_telefon';
  338.                     $wynik ['alerts'][] = "Numer telefonu wyglada na nieprawidłowy.";
  339.                 }
  340.             }
  341.             if ($wynik ['input']['telefon_komorkowy'] != "") {
  342.                 if (!$PHONEV->check($wynik ['input']['telefon_komorkowy'])) {
  343.                     $wynik ['items'][] = 'mask_telefon_komorkowy';
  344.                     $wynik ['alerts'][] = "Numer telefonu komórkowego wyglada na nieprawidłowy.";
  345.                 }                
  346.             }
  347.         }
  348.         if ($wynik ['input']["email"] == "") {
  349.             $wynik ['items'][] = "email";
  350.             $wynik ['alerts'][] = "Adres e-mail nie może być pusty.";
  351.         } else {
  352.             if (!filter_var($wynik ['input']['email'], FILTER_VALIDATE_EMAIL)) {
  353.                 $wynik ['items'][] = "email";
  354.                 $wynik ['alerts'][] = "podany adres e-mail (\"" $wynik ['input']['email'] . "\") jest nieprawidłowy.";                
  355.             }
  356.         }
  357.         if ($rodzaj_klienta) {
  358.             if (strtolower($rodzaj_klienta->getNazwa()) == "osoba prywatna") {
  359.                 if ($wynik ['input']["imie_i_nazwisko"] == "") {
  360.                     $wynik ['items'][] = "imie_i_nazwisko";
  361.                     $wynik ['alerts'][] = "Prosze podać imię i nazwisko.";
  362.                 }
  363.                 if ($wynik ['input']["pesel"] == "") {
  364.                     $wynik ['items'][] = "pesel";
  365.                     $wynik ['alerts'][] = "Numer PESEL nie może być pusty.";
  366.                 } else {
  367.                     if (!$PV->check($wynik ['input']['pesel'])) {
  368.                         $wynik ['items'][] = "pesel";
  369.                         $wynik ['alerts'][] = "Podany numer PESEL nie jest prawidlowy.";
  370.                     }
  371.                 }
  372.             } elseif (strtolower($rodzaj_klienta->getNazwa()) == "firma") {
  373.                 if ($wynik ['input']["nip"] == "") {
  374.                     $wynik ['items'][] = "nip";
  375.                     $wynik ['alerts'][] = "numer NIP nie może być pusty.";
  376.                 } else {
  377.                     if (!$NV->check($wynik ['input']['nip'])) {
  378.                         $wynik ['items'][] = "nip";
  379.                         $wynik ['alerts'][] = "Podany numer NIP nie jest prawidlowy.";
  380.                     }
  381.                 }
  382.                 if ($wynik ['input']["nazwa"] == "") {
  383.                     $wynik ['items'][] = "nazwa";
  384.                     $wynik ['alerts'][] = "Prosze podać nazwe firmy.";
  385.                 }
  386.                 if ($wynik ['input']["osoba_kontaktowa"] == "") {
  387.                     $wynik ['items'][] = "osoba_kontaktowa";
  388.                     $wynik ['alerts'][] = "Prosze wskazac osobe do kontaktu.";
  389.                 }
  390.             }
  391.         }
  392.         return $wynik;
  393.     }
  394.     /**
  395.      * Zasób sprawdza, czy można zarejestrować klienta na podstawie wypełnionego formularza.
  396.      * @Route ("/check-registration-form", name="check-form-registration", methods={"POST"})
  397.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  398.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  399.      * @param \App\Service\phoneVerify $PHONEV
  400.      * @param \App\Service\NIPVerify $NV
  401.      * #param \App\Service\PESELVerify $PV
  402.      * @param \App\Service\PasswordVerify $PASV
  403.      * @return \Symfony\Component\HttpFoundation\JsonResponse Zwraca status TRUE, gdy wszystko OK
  404.      */
  405.     public function checkRegistrationForm(\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie, \App\Service\phoneVerify $PHONEV, \App\Service\NIPVerify $NV, \App\Service\PESELVerify $PV, \App\Service\PasswordVerify $PASV): \Symfony\Component\HttpFoundation\JsonResponse {
  406.         $wynik $this->checkFieldsInRegistrationForm($EM$zadanie$PHONEV$NV$PV$PASV);
  407.         $wynik ['post'] = $_POST;
  408.         $wynik ['status'] = (count($wynik ['alerts']) == 0);
  409.         return new \Symfony\Component\HttpFoundation\JsonResponse($wynik);
  410.     }
  411.     /**
  412.      * Zasób rejestruje nowego klienta.
  413.      * @Route ("/tregistrationNewUser", name="register-new-user", methods={"POST"})
  414.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  415.      * @param \Symfony\Component\HttpFoundation\Request $zadanie
  416.      * @param \App\Service\NIPVerify $NV
  417.      * @param \App\Service\PESELVerify $PV
  418.      * @param \App\Service\PasswordVerify $PASV
  419.      * @param \App\Service\Cezar $CEZAR
  420.      * @return \Symfony\Component\HttpFoundation\JsonResponse
  421.      */
  422.     public function registerNewUser(\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\HttpFoundation\Request $zadanie, \App\Service\phoneVerify $PHONEV, \App\Service\NIPVerify $NV, \App\Service\PESELVerify $PV, \App\Service\PasswordVerify $PASV, \App\Service\Cezar $CEZAR): \Symfony\Component\HttpFoundation\JsonResponse {
  423.         $wynik $this->checkFieldsInRegistrationForm($EM$zadanie$PHONEV$NV$PV$PASV);
  424.         $wynik ['status'] = (count($wynik ['alerts']) == 0);
  425.         if ($wynik ['status']) {
  426.             $U = new \App\Entity\Klient ();
  427.             $EM->persist($U);
  428.             $U->setCrDate(new \DateTime());
  429.             $U->setCzyAdresKoresp($wynik ['input']['adres_koresp']);
  430.             $U->setCzyFakturaNaEmail(true);
  431.             $U->setCzyFakturaPoczta(false);
  432.             $U->setCzyHrd(false);
  433.             $U->setCzyZWww(true);
  434.             $U->setDelDate(null);
  435.             $U->setEmail($wynik ['input']['email']);
  436.             $U->setEmailFaktura($wynik ['input']['email']);
  437.             $U->setKod($wynik ['input']['kod_pocztowy']);
  438.             if ($wynik ['input']['adres_koresp']) {
  439.                 $U->setKorespKod($wynik ['input']['kores_kod_pocztowy']);
  440.                 $U->setKorespKraj($EM->getRepository(\App\Entity\SlownikKrajISO::class)->find(intval($wynik ['input']['kores_kraj'])));
  441.                 $U->setKorespMiasto($wynik ['input']['kores_miasto']);
  442.                 $U->setKorespUlica($wynik ['input']['kores_ulica']);
  443.             }
  444.             $U->setKraj($EM->getRepository(\App\Entity\SlownikKrajISO::class)->find(intval($wynik ['input']['kraj'])));
  445.             $U->setLogin($wynik ['input']['login']);
  446.             $U->setMiasto($wynik ['input']['miasto']);
  447.             $U->setRodzajKlientaHrd($wynik ['input']['rodzaj_klienta']);
  448.             if ($wynik ['input']['rodzaj_klienta']->getNazwa() == "firma") {
  449.                 $U->setNazwa($wynik ['input']['nazwa']);
  450.                 $U->setNip($wynik ['input']['nip']);
  451.                 $CLEAN "";
  452.                 for ($n 0$n strlen($wynik ['input']['nip']); $n++) {
  453.                     if (($wynik ['input']['nip'][$n] >= "0") && ($wynik ['input']['nip'][$n] <= "9"))
  454.                         $CLEAN .= $wynik ['input']['nip'][$n];
  455.                 }
  456.                 $U->setNipCzysty($CLEAN);
  457.                 $U->setWlasciciel($wynik ['input']['osoba_kontaktowa']);
  458.             } else {
  459.                 $U->setNazwa($wynik ['input']['imie_i_nazwisko']);
  460.                 $U->setPesel($wynik ['input']['pesel']);
  461.                 $U->setZgodaNaPokazanieDanychWhois($wynik ['input']['whois']);
  462.             }
  463.             $U->setPassword($wynik ['input']['pass1']);
  464.             $U->setRoles(["ROLE_USER"]);
  465.             $U->setSRCID(0);
  466.             if ($wynik ['input']['telefon'] != "")
  467.                 $U->setTelefon($wynik ['input']['telefon']);
  468.             if ($wynik ['input']['telefon_komorkowy']) {
  469.                 $U->setTelefonKom($wynik ['input']['telefon_komorkowy']);
  470.                 $U->setTelefonPowiadomieniaSms($wynik ['input']['telefon_komorkowy']);
  471.             }
  472.             $U->setUlica($wynik ['input']['ulica']);
  473.             $U->setUpDate(new \DateTime());
  474.             $U->setCzyAktywowany(false);
  475.             $EM->persist($U);
  476.             $EM->flush ();
  477.             
  478.             $wynik ['klientId'] = $U->getId ();
  479.             // Create the Transport
  480.             $transport = new \Swift_SmtpTransport(
  481.                 $EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, serwer""mail.ndc.pl"),
  482.                 intval ($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, port""465")),
  483.                 intval ($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, szyfrowanie""TLS"))
  484.             );
  485.             $transport->setUsername($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, skrzynka""info@ndc.pl"));
  486.             $transport->setPassword($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, hasło"""));
  487.             // Create the Mailer using your created Transport
  488.             $mailer = new \Swift_Mailer($transport);
  489.             // Create a message
  490.             $message = new \Swift_Message($EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Temat maila aktywacyjnego konto""Aktywacja konta w systemie InforpolNet"));
  491.             $message->setFrom([
  492.                 $EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, adres""info@ndc.pl") => $EM->getRepository (\App\Entity\Konfiguracja::class)->peek ("Skrzynka pocztowa, nazwa""InforPol NET")
  493.             ]);
  494.             $message->setTo([$U->getEmail() => $U->getNazwa()]);
  495.             $message->setBody(
  496.                 $this->renderView("email/aktywacja.html.twig", [
  497.                     "linkId" => $CEZAR->match(md5(date ("Y-m-d")) . " " strval($U->getId()) . " " md5(strval($U->getId()))),
  498.                     "timeout" => date ("Y-m-d H:i:s"$U->getCrDate()->getTimestamp() + intval ($EM->getRepository(\App\Entity\Konfiguracja::class)->peek ("Czas na aktywację konta [s]""900")))
  499.                 ]),
  500.                 'text/html'
  501.             );
  502.             try {
  503.                 $result $mailer->send($message);
  504.             } catch (\Exception $e) {
  505.                 $wynik ['status'] = false;
  506.                 $wynik ['alerts'] = [$e->getMessage()];
  507.             }
  508.         }
  509.         return new \Symfony\Component\HttpFoundation\JsonResponse($wynik);
  510.     }
  511.     /**
  512.      * Zasób dokonuje aktywacji konta
  513.      * @Route ("/activate/{link}", name="activate_account", methods={"GET"})
  514.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  515.      * @param \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $PHI
  516.      * @param \App\Service\Cezar $CEZAR
  517.      * @param \App\Service\phoneVerify $PV
  518.      * @param string $link
  519.      * @return Response
  520.      */
  521.     public function activateAccount (\Doctrine\ORM\EntityManagerInterface $EM, \Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface $PHI, \App\Service\Cezar $CEZAR, \App\Service\phoneVerify $PVstring $link): Response {
  522.         $l $CEZAR->demath($link);
  523.         $l explode (" "$l);
  524.         if (count ($l) != 3) {
  525.             //Zły link
  526.             return $this->render ("activationNotFound.html.twig", [ "linkId" => $link ]);
  527.         } else {
  528.             if (md5($l[1]) != $l [2]) {
  529.                 //Zły link
  530.                 return $this->render ("activationNotFound.html.twig", [ "linkId" => $link ]);
  531.             } else {
  532.                 $klient $EM->getRepository(\App\Entity\Klient::class)->find (intval ($l [1]));
  533.                 if ($klient) {
  534.                     //jest klient
  535.                     if ($klient->isCzyAktywowany()) {
  536.                         //Konto jest już aktywne
  537.                         return $this->render("alreadyActivation.html.twig", [ "klient" => $klient ]);
  538.                     } else {
  539.                         if ((time () - $klient->getCrDate()->getTimestamp()) > intval ($EM->getRepository(\App\Entity\Konfiguracja::class)->peek ("Czas na aktywację konta [s]""900"))) {
  540.                             $EM->remove($klient);
  541.                             $EM->flush ();
  542.                             //Link się zdeaktywował, konieczność ponownego zarejestrowania
  543.                             return $this->render("activationLinkIsDeprecated.html.twig", [ "linkId" => $link ]);
  544.                         } else {
  545.                             //Wszystko OK, konto zostało aktywowane
  546.                             $EM->persist($klient);
  547.                             $klient->setCzyAktywowany(true);
  548.                             $klient->setPassword($PHI->hashPassword ($klient$klient->getPassword ()));
  549.                             $klient->setUpDate(new \DateTime ());
  550.                             $EM->flush ();
  551.                             //Tworzenie CSA dla klienta
  552.                             $telefon1 $klient->getTelefonKom();
  553.                             $telefon2 $klient->getTelefon();
  554.                             if ($telefon2 == null$telefon2 $klient->getTelefonKom ();
  555.                             if ($telefon1 != null$telefon1 $PV->convertPhoneToHRDFormat($telefon1);
  556.                             if ($telefon2 != null$telefon2 $PV->convertPhoneToHRDFormat($telefon2);
  557.                             try {
  558.                                 $HRD = \HRDBase\Api\HRDApi::getInstance([
  559.                                             "apiHash" => $EM->getRepository(\App\Entity\Konfiguracja::class)->peek("HRD API HASH"),
  560.                                             "apiLogin" => $EM->getRepository(\App\Entity\Konfiguracja::class)->peek("HRD API LOGIN"),
  561.                                             "apiPass" => $EM->getRepository(\App\Entity\Konfiguracja::class)->peek("HRD API PASS")
  562.                                 ]);
  563.                             } catch (\HRDBase\Api\Exceptions\HRDApiIncorrectDataException $e) {
  564.                                 return new \Symfony\Component\HttpFoundation\JsonResponse ([ "SUCCESS" => false"MESSAGE" => "HRDBase\Api\Exceptions\HRDApiIncorrectDataException: " $e->getMessage ()]);
  565.                             }
  566.                             $HRDTOKEN $HRD->getToken();
  567.                             if ($HRDTOKEN) {
  568.                                 $error false;
  569.                                 if (strtolower ($klient->getRodzajKlientaHrd()->getNazwa()) == "firma") {
  570.                                     //CSA FIRMOWE
  571.                                     try {
  572.                                         $CSANUM $HRD->userCreate(
  573.                                             "company",
  574.                                             $klient->getNipCzysty(),
  575.                                             $klient->getEmail(),
  576.                                             $telefon1,
  577.                                             $telefon2,
  578.                                             null,
  579.                                             $klient->getNazwa(),
  580.                                             $klient->getUlica(),
  581.                                             $klient->getKod(),
  582.                                             $klient->getMiasto(),
  583.                                             $klient->getKraj()->getSkrot2(),
  584.                                             $klient->getWlasciciel()
  585.                                             );
  586.                                     } catch (\Exception $e) {
  587.                                         $error true;
  588.                                     }
  589.                                 } else {
  590.                                     //CSA OSOBY FIZYCZNEJ
  591.                                     try {
  592.                                         $CSANUM $HRD->userCreate(
  593.                                             "person",
  594.                                             $klient->getPesel(),
  595.                                             $klient->getEmail(),
  596.                                             $telefon1,
  597.                                             $telefon2,
  598.                                             null,
  599.                                             $klient->getNazwa(),
  600.                                             $klient->getUlica(),
  601.                                             $klient->getKod(),
  602.                                             $klient->getMiasto(),
  603.                                             $klient->getKraj()->getSkrot2()
  604.                                             );
  605.                                     } catch (\Exception $e) {
  606.                                         $error true;
  607.                                     }
  608.                                 }
  609.                                 if (!$error) {
  610.                                     $CSA = new \App\Entity\KlientCSA ();
  611.                                     $EM->persist($CSA);
  612.                                     $CSA->setCrDate(new \DateTime ());
  613.                                     $CSA->setHrdCsa($CSANUM);
  614.                                     $CSA->setKlient($klient);
  615.                                     $CSA->setSRCID(0);
  616.                                     $CSA->setUpDate(new \DateTime ());
  617.                                     $EM->flush();
  618.                                     $TASK = new \App\Entity\Task ();
  619.                                     $EM->persist($TASK);
  620.                                     $TASK->setArgs([ $CSA->getId() ]);
  621.                                     $TASK->setCrDate(new \DateTime ());
  622.                                     $TASK->setIloscprob(3);
  623.                                     $TASK->setOpcode(\App\Entity\Task::opUPDATE_CSA_INFO);
  624.                                     $TASK->setProba(0);
  625.                                     $TASK->setStatus(\App\Entity\Task::stWAIT);
  626.                                     $TASK->setTermin(new \DateTime (date ("Y-m-d H:i:s"time () + 60)));
  627.                                     $TASK->setUpDate($TASK->getCrDate());                                    
  628.                                     $EM->flush ();
  629.                                 }
  630.                             }
  631.                             return $this->render("activationOK.html.twig", [ "klient" => $klient ]);
  632.                         }
  633.                     }
  634.                 } else {
  635.                     //Klient nie odnaleziony
  636.                     return $this->render ("activationNotFound.html.twig", [ "linkId" => $link ]);
  637.                 }                
  638.             }
  639.         }
  640.     }
  641.     
  642.     /**
  643.      * Zasób wyświetla informację o konieczności aktywowania konta.
  644.      * @Route ("/must-activation/{klientId}", name="register-new-user-activation-info", methods={"GET"})
  645.      * @param \Doctrine\ORM\EntityManagerInterface $EM
  646.      * @param int $klientId
  647.      * @return Response
  648.      */
  649.     public function registerNewUserActivationInfo (\Doctrine\ORM\EntityManagerInterface $EMint $klientId): Response {
  650.         $k $EM->getRepository (\App\Entity\Klient::class)->find ($klientId);
  651.         $timeout_val intval ($EM->getRepository(\App\Entity\Konfiguracja::class)->peek ("Czas na aktywację konta [s]""900"));
  652.         $timeout date ("Y-m-d H:i:s"$k->getCrDate()->getTimestamp () + $timeout_val);
  653.         return $this->render ("mustActivationInfo.html.twig", [
  654.             "klient" => $k,
  655.             "timeout" => $timeout
  656.         ]);
  657.     }
  658.     
  659. }