Controller/SecurityController.php
public function resettingPassword(Request $request, UserPasswordEncoderInterface $encoder, EventDispatcherInterface $dispatcher, \Swift_Mailer $mailer, TranslatorInterface $translator, $token)
    {
        // Get Doctrine
        $em = $this->getDoctrine()->getManager();

        // Find User
        $user = $em->getRepository($this->getParameter('pd_user.user_class'))->findOneBy(['confirmationToken' => $token]);
        if (null === $user) {
            throw $this->createNotFoundException(sprintf($translator->trans('security.token_notfound'), $token));
        }

        // Build Form
        $form = $this->createForm(ResettingPasswordType::class, $user);

        // Handle Form Submit
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            // Encode Password & Set Token
            $password = $encoder->encodePassword($user, $form->get('plainPassword')->getData());
            $user->setPassword($password)
                ->setConfirmationToken(null)
                ->setPasswordRequestedAt(null);

            // Save User
            $em->persist($user);
            $em->flush();

            // Dispatch Register Event
            if ($response = $dispatcher->dispatch(UserEvent::RESETTING_COMPLETE, new UserEvent($user))->getResponse()) {
                return $response;
            }

            // Send Resetting Complete
            $this->sendEmail($user, $mailer, 'Account Password Resetting', 'Password resetting completed.', 'Resetting_Completed');

            // Render Success
            return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resettingSuccess.html.twig', [
                'sendEmail' => false,
            ]);
        }

        // Render
        return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resettingPassword.html.twig', [
            'token' => $token,
            'form' => $form->createView(),
        ]);
    }
public function resettingPassword(Request $request, UserPasswordEncoderInterface $encoder, EventDispatcherInterface $dispatcher, \Swift_Mailer $mailer, TranslatorInterface $translator, $token)
    {
        // Get Doctrine
        $em = $this->getDoctrine()->getManager();

        // Find User
        $user = $em->getRepository($this->getParameter('pd_user.user_class'))->findOneBy(['confirmationToken' => $token]);
        if (null === $user) {
            throw $this->createNotFoundException(sprintf($translator->trans('security.token_notfound'), $token));
        }

        // Build Form
        $form = $this->createForm(ResettingPasswordType::class, $user);

        // Handle Form Submit
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            // Encode Password & Set Token
            $password = $encoder->encodePassword($user, $form->get('plainPassword')->getData());
            $user->setPassword($password)
                ->setConfirmationToken(null)
                ->setPasswordRequestedAt(null);

            // Save User
            $em->persist($user);
            $em->flush();

            // Dispatch Register Event
            if ($response = $dispatcher->dispatch(UserEvent::RESETTING_COMPLETE, new UserEvent($user))->getResponse()) {
                return $response;
            }

            // Send Resetting Complete
            $this->sendEmail($user, $mailer, 'Account Password Resetting', 'Password resetting completed.', 'Resetting_Completed');

            // Render Success
            return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resettingSuccess.html.twig', [
                'sendEmail' => false,
            ]);
        }

        // Render
        return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resettingPassword.html.twig', [
            'token' => $token,
            'form' => $form->createView(),
        ]);
    }
public function resettingPassword ( Request $ request , UserPasswordEncoderInterface $ encoder , EventDispatcherInterface $ dispatcher , \ Swift_Mailer $ mailer , TranslatorInterface $ translator , $ token ) { // Get Doctrine $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; // Find User $ user = $ em -> getRepository ( $ this -> getParameter ( 'pd_user.user_class' ) ) -> findOneBy ( [ 'confirmationToken' => $ token ] ) ; if ( null === $ user ) { throw $ this -> createNotFoundException ( sprintf ( $ translator -> trans ( 'security.token_notfound' ) , $ token ) ) ; } // Build Form $ form = $ this -> createForm ( ResettingPasswordType :: class , $ user ) ; // Handle Form Submit $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { // Encode Password & Set Token $ password = $ encoder -> encodePassword ( $ user , $ form -> get ( 'plainPassword' ) -> getData ( ) ) ; $ user -> setPassword ( $ password ) -> setConfirmationToken ( null ) -> setPasswordRequestedAt ( null ) ; // Save User $ em -> persist ( $ user ) ; $ em -> flush ( ) ; // Dispatch Register Event if ( $ response = $ dispatcher -> dispatch ( UserEvent :: RESETTING_COMPLETE , new UserEvent ( $ user ) ) -> getResponse ( ) ) { return $ response ; } // Send Resetting Complete $ this -> sendEmail ( $ user , $ mailer , 'Account Password Resetting' , 'Password resetting completed.' , 'Resetting_Completed' ) ; // Render Success return $ this -> render ( $ this -> getParameter ( 'pd_user.template_path' ) . '/Resetting/resettingSuccess.html.twig' , [ 'sendEmail' => false , ] ) ; } // Render return $ this -> render ( $ this -> getParameter ( 'pd_user.template_path' ) . '/Resetting/resettingPassword.html.twig' , [ 'token' => $ token , 'form' => $ form -> createView ( ) , ] ) ; }
Reset Password Form.

@param Request $request
@param $token

@return \Symfony\Component\HttpFoundation\Response
Reset Password Form .