src/Controller/TinyKnightGames/Authentication/RegistrationController.php line 20
<?php
namespace App\Controller\TinyKnightGames\Authentication;
use App\Entity\User;
use App\Form\RegistrationFormType;
use App\Service\UserUpkeep;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
class RegistrationController extends AbstractController
{
public function __construct(private ManagerRegistry $doctrine) {}
#[Route('/register', name: 'app_register')]
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasherInterface, UserUpkeep $userUpkeep): Response
{
$user = new User();
$form = $this->createForm(RegistrationFormType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// encode the plain password
$user->setPassword(
$userPasswordHasherInterface->hashPassword(
$user,
$form->get('plainPassword')->getData()
)
);
$em = $this->doctrine->getManager();
$em->persist($user);
// Give User starting Equipment
$userUpkeep->addStartingEquipment($user);
// $startingEquipment = ['Old Fishing Rod','Old Fishing Lure','Old Hat','Old Shirt', 'Old Tacklebox','Old Boots'];
// foreach ($startingEquipment as $equipment) {
// $newEquipment = new InventoryEquipment();
// $newEquipment->setUser($user);
// $newEquipment->setEquipment($entityManager->getRepository(Equipment::class)->findOneBy(array('name' => $equipment)));
// $newEquipment->setQuantity(1);
// $newEquipment->setIsEquipped(1);
// $entityManager->persist($newEquipment);
// }
// Setup User Catchable Stats
$userUpkeep->addTemplateStats($user);
// $catchables = $entityManager->getRepository(Catchable::class)->findAll();
// foreach($catchables as $catchable) {
// $stat = new UserRecord();
// $stat->setUser($user);
// $stat->setCatchable($catchable);
// $stat->setCaughtQty(0);
// $stat->setSalvageQty(0);
// $stat->setConvertNftQty(0);
// $entityManager->persist($stat);
// }
// Instantiate UserGears for each gear slot (EquipmentCategory) available
$userUpkeep->addUserGearSlots($user);
// $gearSlots = $entityManager->getRepository(EquipmentCategory::class)->findAll();
// foreach ($gearSlots as $gearSlot) {
// $slot = new UserGear();
// $slot->setUser($user);
// $slot->setEquipmentCategory($gearSlot);
// $entityManager->persist($slot);
// }
$em->persist($user);
$em->flush();
// do anything else you need here, like send an email
return $this->redirectToRoute('index');
}
return $this->render('registration/register.html.twig', [
'registrationForm' => $form->createView(),
]);
}
}