vendor/symfonycasts/reset-password-bundle/src/Controller/ResetPasswordControllerTrait.php line 74

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the SymfonyCasts ResetPasswordBundle package.
  4.  * Copyright (c) SymfonyCasts <https://symfonycasts.com/>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace SymfonyCasts\Bundle\ResetPassword\Controller;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordToken;
  12. /**
  13.  * Provides useful methods to a "reset password controller".
  14.  *
  15.  * Use of this trait requires a controller to extend
  16.  * Symfony\Bundle\FrameworkBundle\Controller\AbstractController
  17.  *
  18.  * @author Jesse Rushlow <jr@rushlow.dev>
  19.  * @author Ryan Weaver   <ryan@symfonycasts.com>
  20.  */
  21. trait ResetPasswordControllerTrait
  22. {
  23.     /**
  24.      * @deprecated since 1.3.0, use ResetPasswordControllerTrait::setTokenObjectInSession() instead.
  25.      */
  26.     private function setCanCheckEmailInSession(): void
  27.     {
  28.         trigger_deprecation(
  29.             'symfonycasts/reset-password-bundle',
  30.             '1.3.0',
  31.             'Storing the ResetPasswordToken object in the session is more desirable, use ResetPasswordControllerTrait::setTokenObjectInSession() instead.'
  32.         );
  33.         $this->getSessionService()->set('ResetPasswordCheckEmail'true);
  34.     }
  35.     /**
  36.      * @deprecated since 1.3.0, use ResetPasswordControllerTrait::getTokenObjectFromSession() instead.
  37.      */
  38.     private function canCheckEmail(): bool
  39.     {
  40.         trigger_deprecation(
  41.             'symfonycasts/reset-password-bundle',
  42.             '1.3.0',
  43.             'Storing the ResetPasswordToken object in the session is more desirable, use ResetPasswordControllerTrait::getTokenObjectFromSession() instead.'
  44.         );
  45.         return $this->getSessionService()->has('ResetPasswordCheckEmail');
  46.     }
  47.     private function storeTokenInSession(string $token): void
  48.     {
  49.         $this->getSessionService()->set('ResetPasswordPublicToken'$token);
  50.     }
  51.     private function getTokenFromSession(): ?string
  52.     {
  53.         return $this->getSessionService()->get('ResetPasswordPublicToken');
  54.     }
  55.     private function setTokenObjectInSession(ResetPasswordToken $token): void
  56.     {
  57.         $token->clearToken();
  58.         $this->getSessionService()->set('ResetPasswordToken'$token);
  59.     }
  60.     private function getTokenObjectFromSession(): ?ResetPasswordToken
  61.     {
  62.         return $this->getSessionService()->get('ResetPasswordToken');
  63.     }
  64.     private function cleanSessionAfterReset(): void
  65.     {
  66.         $session $this->getSessionService();
  67.         $session->remove('ResetPasswordPublicToken');
  68.         $session->remove('ResetPasswordCheckEmail');
  69.         $session->remove('ResetPasswordToken');
  70.     }
  71.     private function getSessionService(): SessionInterface
  72.     {
  73.         /** @var Request $request */
  74.         $request $this->container->get('request_stack')->getCurrentRequest();
  75.         return $request->getSession();
  76.     }
  77. }