src/Controller/AccountController.php line 24
<?phpnamespace App\Controller;use DateTimeImmutable;use App\Entity\Account;use App\Entity\AccountLog;use Symfony\Component\Uid\Ulid;use App\Entity\CompletedDialogue;use App\Repository\AccountRepository;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Form\Extension\Core\Type\SubmitType;use Symfony\Component\Form\Extension\Core\Type\PasswordType;use Symfony\Component\Form\Extension\Core\Type\RepeatedType;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;class AccountController extends AbstractController{#[Route(path: '/change/{hash}', name: 'api_change')]public function change(Request $request, $hash, AccountRepository $accountRepository, UserPasswordHasherInterface $accountPasswordHasher): Response{$isValid = Ulid::isValid($hash);if (!$isValid) {return $this->render('security/info.html.twig', ['title' => 'Błąd','text' => 'Błędny link!',]);}$account = $accountRepository->findOneBy(['hash' => $hash]);if (is_null($account)) {return $this->render('security/info.html.twig', ['title' => 'Błąd','text' => 'Brak konta!',]);}$date = new DateTimeImmutable('now -2 hours');if ($account->getHashedAt() < $date) {return $this->render('security/info.html.twig', ['title' => 'Błąd','text' => 'Nieważny link!',]);}$defaultData = ['message' => 'Type your message here'];$form = $this->createFormBuilder($defaultData)->add('plainPassword', RepeatedType::class, ['type' => PasswordType::class,'invalid_message' => 'The password fields must match.','options' => ['attr' => ['class' => 'password-field']],'required' => true,'first_options' => ['label' => 'Nowe hasło'],'second_options' => ['label' => 'Powtórz hasło'],'attr' => ['autocomplete' => 'off'],])->add('submit', SubmitType::class)->getForm();$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$data = $form->getData();$password = $data['plainPassword'];$account->setPassword($accountPasswordHasher->hashPassword($account, $password));$account->setHash(null);$account->setHashedAt(null);$accountRepository->save($account, true);return $this->render('security/info.html.twig', ['title' => 'Sukces','text' => 'Hasło zostało zmienione',]);}return $this->render('security/change.html.twig', ['form' => $form,'error' => false,]);}// #[Route("/account/{id}/delete", name: "app_account_delete")]// public function delete(Account $account, EntityManagerInterface $entityManager): Response// {// $completedDialogues = $account->getCompletedDialogues();// foreach ($completedDialogues as $completedDialogue) {// $entityManager->remove($completedDialogue);// }// $accountLogs = $entityManager->getRepository(AccountLog::class)->findBy(['objectId' => $account->getId()]);// foreach ($accountLogs as $accountLog) {// $entityManager->remove($accountLog);// }// $accountBlocks = $account->getAccountBlocks();// foreach ($accountBlocks as $accountBlock) {// $entityManager->remove($accountBlock);// }// $entityManager->remove($account);// $entityManager->flush();// return new Response();// }}