src/AppBundle/Controller/User/ResettingController.php
/**
     * Request reset user password: submit form and send email.
     *
     * @param Request $request
     *
     * @return Response
     */
Request reset user password: submit form and send email.
@param Request $request

@return Response
Request reset user password : submit form and send email . @param Request $request @return Response
public function sendEmailAction(Request $request)
    {
        $username = $request->request->get('username');
        $user = $this->get('fos_user.user_manager')->findUserByUsernameOrEmail($username);
        $dispatcher = $this->get('event_dispatcher');
        $event = new GetResponseNullableUserEvent($user, $request);
        $dispatcher->dispatch(FOSUserEvents::RESETTING_SEND_EMAIL_INITIALIZE, $event);
        if (null !== $event->getResponse()) {
            return $event->getResponse();
        }
        $ttl = $this->container->getParameter('fos_user.resetting.retry_ttl');
        if (null !== $user && !$user->isPasswordRequestNonExpired($ttl)) {
            $event = new GetResponseUserEvent($user, $request);
            $dispatcher->dispatch(FOSUserEvents::RESETTING_RESET_REQUEST, $event);
            if (null !== $event->getResponse()) {
                return $event->getResponse();
            }
            if (null === $user->getConfirmationToken()) {
                $tokenGenerator = $this->get('fos_user.util.token_generator');
                $user->setConfirmationToken($tokenGenerator->generateToken());
            }
            $event = new GetResponseUserEvent($user, $request);
            $dispatcher->dispatch(FOSUserEvents::RESETTING_SEND_EMAIL_CONFIRM, $event);
            if (null !== $event->getResponse()) {
                return $event->getResponse();
            }
            $this->get('fos_user.mailer')->sendResettingEmailMessage($user);
            $user->setPasswordRequestedAt(new \DateTime());
            $this->get('fos_user.user_manager')->updateUser($user);
            $event = new GetResponseUserEvent($user, $request);
            $dispatcher->dispatch(FOSUserEvents::RESETTING_SEND_EMAIL_COMPLETED, $event);
            if (null !== $event->getResponse()) {
                return $event->getResponse();
            }
        }
        return new RedirectResponse($this->generateUrl('app_user_resetting_check_email', array('username' => $username)));
    }
public function sendEmailAction ( Request $ request ) { $ username = $ request -> request -> get ( 'username' ) ; $ user = $ this -> get ( 'fos_user.user_manager' ) -> findUserByUsernameOrEmail ( $ username ) ; $ dispatcher = $ this -> get ( 'event_dispatcher' ) ; $ event = new GetResponseNullableUserEvent ( $ user , $ request ) ; $ dispatcher -> dispatch ( FOSUserEvents :: RESETTING_SEND_EMAIL_INITIALIZE , $ event ) ; if ( null !== $ event -> getResponse ( ) ) { return $ event -> getResponse ( ) ; } $ ttl = $ this -> container -> getParameter ( 'fos_user.resetting.retry_ttl' ) ; if ( null !== $ user && ! $ user -> isPasswordRequestNonExpired ( $ ttl ) ) { $ event = new GetResponseUserEvent ( $ user , $ request ) ; $ dispatcher -> dispatch ( FOSUserEvents :: RESETTING_RESET_REQUEST , $ event ) ; if ( null !== $ event -> getResponse ( ) ) { return $ event -> getResponse ( ) ; } if ( null === $ user -> getConfirmationToken ( ) ) { $ tokenGenerator = $ this -> get ( 'fos_user.util.token_generator' ) ; $ user -> setConfirmationToken ( $ tokenGenerator -> generateToken ( ) ) ; } $ event = new GetResponseUserEvent ( $ user , $ request ) ; $ dispatcher -> dispatch ( FOSUserEvents :: RESETTING_SEND_EMAIL_CONFIRM , $ event ) ; if ( null !== $ event -> getResponse ( ) ) { return $ event -> getResponse ( ) ; } $ this -> get ( 'fos_user.mailer' ) -> sendResettingEmailMessage ( $ user ) ; $ user -> setPasswordRequestedAt ( new \ DateTime ( ) ) ; $ this -> get ( 'fos_user.user_manager' ) -> updateUser ( $ user ) ; $ event = new GetResponseUserEvent ( $ user , $ request ) ; $ dispatcher -> dispatch ( FOSUserEvents :: RESETTING_SEND_EMAIL_COMPLETED , $ event ) ; if ( null !== $ event -> getResponse ( ) ) { return $ event -> getResponse ( ) ; } } return new RedirectResponse ( $ this -> generateUrl ( 'app_user_resetting_check_email' , array ( 'username' => $ username ) ) ) ; }
Request reset user password: submit form and send email.
Request reset user password : submit form and send email .
/** @var $user UserInterface */ /** @var $dispatcher EventDispatcherInterface */ /* Dispatch init event */ /** @var $tokenGenerator TokenGeneratorInterface */ /* Dispatch confirm event */ /* Dispatch completed event */