Ejemplo n.º 1
0
 /**
  * Generates a new token for a new user.
  *
  * @param UserInterface $user
  *
  * @throws TokenAlreadyRequestedException
  */
 private function generateTokenForUser(UserInterface $user)
 {
     // if a token was already requested within the request interval time frame
     if ($user->getPasswordResetToken() !== null && $this->dateIsInRequestFrame($user->getPasswordResetTokenExpiresAt())) {
         throw new TokenAlreadyRequestedException(self::getRequestInterval());
     }
     $em = $this->getDoctrine()->getManager();
     $user->setPasswordResetToken($this->getToken());
     $expireDateTime = (new \DateTime())->add(self::getResetInterval());
     $user->setPasswordResetTokenExpiresAt($expireDateTime);
     $user->setPasswordResetTokenEmailsSent(0);
     $em->persist($user);
     $em->flush();
 }