src/Controller/User/RegistrationController.php line 38
<?phpnamespace App\Controller\User;use App\Controller\AppController;use App\Entity\User;use App\Form\User\RegistrationForm;use App\Handler\MessageTrait;use App\Service\User\RegistrationService;use ReCaptcha\ReCaptcha;use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;use Twig\Error\LoaderError;use Twig\Error\RuntimeError;use Twig\Error\SyntaxError;/*** Class RegistrationController* @package App\Controller\User* @Route("/registracija")*/class RegistrationController extends AppController{use AuthTrait;/*** @Route(name="register")* @param RegistrationService $service* @param ParameterBagInterface $parameterBag* @return RedirectResponse|Response* @throws LoaderError* @throws RuntimeError* @throws SyntaxError*/public function create(RegistrationService $service, ParameterBagInterface $parameterBag){// Ako je korisnik logiran, vrati ga na home pageif ($this->isGranted('ROLE_USER')) {return $this->redirectToRoute('home');}$checkbox = $this->getRequest()->get('registration-checkbox-slazese');$recaptchaPublicKey = $parameterBag->get('google_recaptcha_site_key');$user = new User();$form = $this->createForm(RegistrationForm::class, $user, ['validation_groups' => ['registration']]);$form->handleRequest($this->getRequest());// Ovo će se na svaki submit izvršiti// Provjera prolazi i ako nije validna forma zbog uvjeta korištenjaif ($form->isSubmitted()) {if (null === $checkbox) {$this->sendCustomMessage(MessageTrait::$error, 'registracija.uvjetiKoristenjaMorajuBitiPrihvaceni');return $this->render('security/registration.html.twig', ['form' => $form->createView(),'checked' => $checkbox,'recaptchaPublicKey' => $recaptchaPublicKey,]);}// Ako su uvjeti prihvaćeni te nema errora na poljima, provjeravaj recaptchuif ($form->isValid()) {$recaptcha = new ReCaptcha($parameterBag->get('google_recaptcha_secret_key'));$resp = $recaptcha->verify($this->getRequest()->request->get('g-recaptcha-response'), $this->getRequest()->getClientIp());if (!$resp->isSuccess()) {$this->sendCustomMessage(MessageTrait::$error, 'registracija.recaptcha');return $this->render('security/registration.html.twig',['form' => $form->createView(),'recaptchaPublicKey' => $recaptchaPublicKey,'checked' => $checkbox]);}// Ako je sve prošlo, uzmi podatke, registriraj korisnika i pošalji e-mail za potvrdu acc-a/** @var User $data */$data = $form->getData();$service->register($data);return $this->redirectToRoute('register-util-after-register');}}return $this->render('security/registration.html.twig', ['form' => $form->createView(),'checked' => $checkbox,'recaptchaPublicKey' => $recaptchaPublicKey,]);}/*** @Route("/provjera-registracije", name="register-util-after-register")*/public function redirectAfterRegister(){return $this->render('security/registration-wait-confirm.html.twig', []);}/*** @param User $user* @param TokenStorageInterface $tokenStorage* @param RegistrationService $service* @return RedirectResponse* @Route("/potvrda-registracije/{registrationToken}", name="registration-confirm")*/public function confirmUser(User $user, TokenStorageInterface $tokenStorage, RegistrationService $service){$service->confirmRegistration($user);$this->authenticateUser($user, $tokenStorage);return $this->redirectToRoute('home');}}