src/Security/Voter/PasswordResetExpiredVoter.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter;
  3. use App\Entity\PasswordReset;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. class PasswordResetExpiredVoter extends Voter
  7. {
  8.     protected function supports(string $attribute$subject): bool
  9.     {
  10.         return in_array($attribute, ['PASSWORD_RESET_NOT_EXPIRED'])
  11.             && $subject instanceof PasswordReset;
  12.     }
  13.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  14.     {
  15.         assert($attribute == 'PASSWORD_RESET_NOT_EXPIRED');
  16.         assert($subject instanceof PasswordReset);
  17.         return $subject->getExpiredAt() >= new \DateTimeImmutable();
  18.     }
  19. }