From d83ed5b6595d5fdb9a255bfaa1f1a0198c4d09e4 Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 1 Nov 2022 16:34:08 +0100 Subject: [PATCH 1/4] fixed return type of findOneRandom --- src/Repository/QuotesRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repository/QuotesRepository.php b/src/Repository/QuotesRepository.php index c84ca94..1e3b7a3 100644 --- a/src/Repository/QuotesRepository.php +++ b/src/Repository/QuotesRepository.php @@ -38,7 +38,7 @@ class QuotesRepository extends ServiceEntityRepository } } - public function findOneRandom(): ?QueryBuilder + public function findOneRandom(): ?Quotes { try { $idLimits = $this->createQueryBuilder(alias: 'q') -- 2.39.5 From b1ce69cc47a1d749b86386fec0f03e26760e7ca6 Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 1 Nov 2022 16:34:47 +0100 Subject: [PATCH 2/4] merged EmailVerifier --- src/Controller/SecurityController.php | 46 +++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 22137cb..5f24a08 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -26,6 +26,7 @@ use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait; use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface; use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface; +use SymfonyCasts\Bundle\VerifyEmail\VerifyEmailHelperInterface; class SecurityController extends AbstractController { @@ -33,7 +34,9 @@ class SecurityController extends AbstractController public function __construct(private readonly EmailVerifier $emailVerifier, private readonly ResetPasswordHelperInterface $resetPasswordHelper, - private readonly EntityManagerInterface $entityManager + private readonly EntityManagerInterface $entityManager, + private readonly VerifyEmailHelperInterface $verifyEmailHelper, + private readonly MailerInterface $mailer, ) { // empty body @@ -88,7 +91,7 @@ class SecurityController extends AbstractController $entityManager->flush(); // generate a signed url and email it to the user - $this->emailVerifier->sendEmailConfirmation(verifyEmailRouteName: 'security_verify_email', user: $user, + $this->sendEmailConfirmation(verifyEmailRouteName: 'security_verify_email', user: $user, email: (new TemplatedEmail()) ->from(new Address(address: 'info@24unix.net', name: '24unix.net')) ->to($user->getEmail()) @@ -124,7 +127,7 @@ class SecurityController extends AbstractController // validate email confirmation link, sets User::isVerified=true and persists try { - $this->emailVerifier->handleEmailConfirmation(request: $request, user: $user); + $this->handleEmailConfirmation(request: $request, user: $user); } catch (VerifyEmailExceptionInterface $exception) { $this->addFlash(type: 'verify_email_error', message: $translator->trans(id: $exception->getReason(), parameters: [], domain: 'VerifyEmailBundle')); @@ -284,4 +287,41 @@ class SecurityController extends AbstractController return $this->redirectToRoute(route: 'security_recovery_mail_sent'); } + + + public function sendEmailConfirmation(string $verifyEmailRouteName, User /* UserInterface */ $user, TemplatedEmail $email): void + { + $signatureComponents = $this->verifyEmailHelper->generateSignature( + routeName: $verifyEmailRouteName, + userId: $user->getId(), + userEmail: $user->getEmail(), + extraParams: ['id' => $user->getId()] + ); + + $context = $email->getContext(); + $context['signedUrl'] = $signatureComponents->getSignedUrl(); + $context['expiresAtMessageKey'] = $signatureComponents->getExpirationMessageKey(); + $context['expiresAtMessageData'] = $signatureComponents->getExpirationMessageData(); + + $email->context(context: $context); + + try { + $this->mailer->send(message: $email); + } catch (TransportExceptionInterface $e) { + die($e->getMessage()); + } + } + + /** + * @throws VerifyEmailExceptionInterface + */ + public function handleEmailConfirmation(Request $request, User /*UserInterface*/ $user): void + { + $this->verifyEmailHelper->validateEmailConfirmation(signedUrl: $request->getUri(), userId: $user->getId(), userEmail: $user->getEmail()); + + $user->setIsVerified(isVerified: true); + + $this->entityManager->persist(entity: $user); + $this->entityManager->flush(); + } } -- 2.39.5 From 388432feb99a53682ebf545169185fb8aad1fb28 Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 1 Nov 2022 16:35:28 +0100 Subject: [PATCH 3/4] merged EmailVerifier --- src/Controller/SecurityController.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 5f24a08..448d76b 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -7,7 +7,6 @@ use App\Form\ChangePasswordFormType; use App\Form\RegistrationFormType; use App\Form\ResetPasswordRequestFormType; use App\Repository\UserRepository; -use App\Security\EmailVerifier; use Doctrine\ORM\EntityManagerInterface; use Exception; use Symfony\Bridge\Twig\Mime\TemplatedEmail; @@ -32,8 +31,7 @@ class SecurityController extends AbstractController { use ResetPasswordControllerTrait; - public function __construct(private readonly EmailVerifier $emailVerifier, - private readonly ResetPasswordHelperInterface $resetPasswordHelper, + public function __construct(private readonly ResetPasswordHelperInterface $resetPasswordHelper, private readonly EntityManagerInterface $entityManager, private readonly VerifyEmailHelperInterface $verifyEmailHelper, private readonly MailerInterface $mailer, -- 2.39.5 From 5cc320d656f52e6afec4e13178965cfcdf10ad83 Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 1 Nov 2022 16:35:43 +0100 Subject: [PATCH 4/4] deletion --- src/Security/EmailVerifier.php | 54 ---------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 src/Security/EmailVerifier.php diff --git a/src/Security/EmailVerifier.php b/src/Security/EmailVerifier.php deleted file mode 100644 index 1d45afc..0000000 --- a/src/Security/EmailVerifier.php +++ /dev/null @@ -1,54 +0,0 @@ -verifyEmailHelper->generateSignature( - routeName: $verifyEmailRouteName, - userId: $user->getId(), - userEmail: $user->getEmail(), - extraParams: ['id' => $user->getId()] - ); - - $context = $email->getContext(); - $context['signedUrl'] = $signatureComponents->getSignedUrl(); - $context['expiresAtMessageKey'] = $signatureComponents->getExpirationMessageKey(); - $context['expiresAtMessageData'] = $signatureComponents->getExpirationMessageData(); - - $email->context(context: $context); - - $this->mailer->send(message: $email); - } - - /** - * @throws VerifyEmailExceptionInterface - */ - public function handleEmailConfirmation(Request $request, User /*UserInterface*/ $user): void - { - $this->verifyEmailHelper->validateEmailConfirmation(signedUrl: $request->getUri(), userId: $user->getId(), userEmail: $user->getEmail()); - - $user->setIsVerified(isVerified: true); - - $this->entityManager->persist(entity: $user); - $this->entityManager->flush(); - } -} -- 2.39.5