src/Sulu/Bundle/SecurityBundle/Controller/ResettingController.php
private function generateTokenForUser(UserInterface $user)
    {
        // if a token was already requested within the request interval time frame
        if (null !== $user->getPasswordResetToken()
            && $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();
    }
private function generateTokenForUser(UserInterface $user)
    {
        // if a token was already requested within the request interval time frame
        if (null !== $user->getPasswordResetToken()
            && $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();
    }
private function generateTokenForUser ( UserInterface $ user ) { // if a token was already requested within the request interval time frame if ( null !== $ user -> getPasswordResetToken ( ) && $ 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 ( ) ; }
Generates a new token for a new user.

@param UserInterface $user

@throws TokenAlreadyRequestedException
Generates a new token for a new user .