src/Controller/RegistrationController.php line 30
<?phpnamespace App\Controller;use App\Entity\User;use App\Repository\UserRepository;use Doctrine\ORM\EntityManagerInterface;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Bundle\SecurityBundle\Security;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;use Symfony\Component\Routing\Annotation\Route;/*** Passenger sign-up for Tuk-n-Tour.** This used to belong to an unrelated "hotel" project — it built a Hotel user,* mailed a verification link (there is no mailer configured) and then sent the* new account to the admin dashboard, which it had no right to see, so /register* simply 500'd. It now does the one thing this app needs: create a passenger,* sign them in, and drop them on the map ready to book.** The form is hand-rolled rather than built with the form component so the page* can carry the app's own look with no theme wrestling.*/class RegistrationController extends AbstractController{#[Route('/register', name: 'app_register', methods: ['GET', 'POST'])]public function register(Request $request,UserPasswordHasherInterface $hasher,EntityManagerInterface $em,UserRepository $users,Security $security,): Response {// Already signed in? Nothing to register.if ($this->getUser()) {return $this->redirectToRoute('page_home');}$old = ['name' => '', 'email' => '', 'phone' => ''];$error = null;if ($request->isMethod('POST')) {$name = trim((string) $request->request->get('name'));$email = trim((string) $request->request->get('email'));$phone = trim((string) $request->request->get('phone'));$password = (string) $request->request->get('password');$old = ['name' => $name, 'email' => $email, 'phone' => $phone];if (!$this->isCsrfTokenValid('register', (string) $request->request->get('_token'))) {$error = 'Your session expired. Please try again.';} elseif ($name === '' || $email === '' || $phone === '' || $password === '') {$error = 'Please fill in every field.';} elseif (!filter_var($email, \FILTER_VALIDATE_EMAIL)) {$error = 'That email address does not look right.';} elseif (mb_strlen($password) < 6) {$error = 'Choose a password of at least 6 characters.';} elseif ($users->findOneBy(['email' => $email]) !== null) {$error = 'An account with this email already exists. Try signing in instead.';} else {$user = new User();$user->setName($name);$user->setEmail($email);$user->setPhone($phone);$user->setRoles(['ROLE_USER']);// No mailer is configured, so accounts are usable immediately.$user->setIsVerified(true);$user->setPassword($hasher->hashPassword($user, $password));$em->persist($user);$em->flush();// Sign them straight in and send them to the map to book.$security->login($user);return $this->redirectToRoute('app_map');}}return $this->render('registration/register.html.twig', ['old' => $old,'error' => $error,]);}}