Controller/SecurityController.php
public function resetting(Request $request, EventDispatcherInterface $dispatcher, \Swift_Mailer $mailer, TranslatorInterface $translator)
    {
        // Check Auth
        if ($this->checkAuth()) {
            return $this->redirectToRoute($this->getParameter('pd_user.login_redirect'));
        }

        // Build Form
        $form = $this->createForm($this->getParameter('pd_user.resetting_type'));

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

        if ($form->isSubmitted() && $form->isValid()) {
            // Get Doctrine
            $em = $this->getDoctrine()->getManager();

            // Find User
            $user = $em->getRepository($this->getParameter('pd_user.user_class'))->findOneBy(['email' => $form->get('username')->getData()]);
            if (null === $user) {
                $form->get('username')->addError(new FormError($translator->trans('security.user_not_found')));
            } else {
                // Create TTL
                if ($user->isPasswordRequestNonExpired($this->getParameter('pd_user.resetting_request_time'))) {
                    $form->get('username')->addError(new FormError($translator->trans('security.resetpw_wait_resendig', ['%s' => $this->getParameter('pd_user.resetting_request_time')])));
                } else {
                    // Create Confirmation Token
                    if (empty($user->getConfirmationToken()) || null === $user->getConfirmationToken()) {
                        $user->createConfirmationToken();
                        $user->setPasswordRequestedAt(new \DateTime());
                    }

                    // Send Resetting Email
                    $emailBody = [
                        'confirmationUrl' => $this->generateUrl('security_resetting_password',
                            ['token' => $user->getConfirmationToken()],
                            UrlGeneratorInterface::ABSOLUTE_URL),
                    ];
                    $this->sendEmail($user, $mailer, 'Account Password Resetting', $emailBody, 'Resetting');

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

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

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

        // Render
        return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resetting.html.twig', [
            'form' => $form->createView(),
        ]);
    }
public function resetting(Request $request, EventDispatcherInterface $dispatcher, \Swift_Mailer $mailer, TranslatorInterface $translator)
    {
        // Check Auth
        if ($this->checkAuth()) {
            return $this->redirectToRoute($this->getParameter('pd_user.login_redirect'));
        }

        // Build Form
        $form = $this->createForm($this->getParameter('pd_user.resetting_type'));

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

        if ($form->isSubmitted() && $form->isValid()) {
            // Get Doctrine
            $em = $this->getDoctrine()->getManager();

            // Find User
            $user = $em->getRepository($this->getParameter('pd_user.user_class'))->findOneBy(['email' => $form->get('username')->getData()]);
            if (null === $user) {
                $form->get('username')->addError(new FormError($translator->trans('security.user_not_found')));
            } else {
                // Create TTL
                if ($user->isPasswordRequestNonExpired($this->getParameter('pd_user.resetting_request_time'))) {
                    $form->get('username')->addError(new FormError($translator->trans('security.resetpw_wait_resendig', ['%s' => $this->getParameter('pd_user.resetting_request_time')])));
                } else {
                    // Create Confirmation Token
                    if (empty($user->getConfirmationToken()) || null === $user->getConfirmationToken()) {
                        $user->createConfirmationToken();
                        $user->setPasswordRequestedAt(new \DateTime());
                    }

                    // Send Resetting Email
                    $emailBody = [
                        'confirmationUrl' => $this->generateUrl('security_resetting_password',
                            ['token' => $user->getConfirmationToken()],
                            UrlGeneratorInterface::ABSOLUTE_URL),
                    ];
                    $this->sendEmail($user, $mailer, 'Account Password Resetting', $emailBody, 'Resetting');

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

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

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

        // Render
        return $this->render($this->getParameter('pd_user.template_path') . '/Resetting/resetting.html.twig', [
            'form' => $form->createView(),
        ]);
    }
public function resetting ( Request $ request , EventDispatcherInterface $ dispatcher , \ Swift_Mailer $ mailer , TranslatorInterface $ translator ) { // Check Auth if ( $ this -> checkAuth ( ) ) { return $ this -> redirectToRoute ( $ this -> getParameter ( 'pd_user.login_redirect' ) ) ; } // Build Form $ form = $ this -> createForm ( $ this -> getParameter ( 'pd_user.resetting_type' ) ) ; // Handle Form Submit $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { // Get Doctrine $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; // Find User $ user = $ em -> getRepository ( $ this -> getParameter ( 'pd_user.user_class' ) ) -> findOneBy ( [ 'email' => $ form -> get ( 'username' ) -> getData ( ) ] ) ; if ( null === $ user ) { $ form -> get ( 'username' ) -> addError ( new FormError ( $ translator -> trans ( 'security.user_not_found' ) ) ) ; } else { // Create TTL if ( $ user -> isPasswordRequestNonExpired ( $ this -> getParameter ( 'pd_user.resetting_request_time' ) ) ) { $ form -> get ( 'username' ) -> addError ( new FormError ( $ translator -> trans ( 'security.resetpw_wait_resendig' , [ '%s' => $ this -> getParameter ( 'pd_user.resetting_request_time' ) ] ) ) ) ; } else { // Create Confirmation Token if ( empty ( $ user -> getConfirmationToken ( ) ) || null === $ user -> getConfirmationToken ( ) ) { $ user -> createConfirmationToken ( ) ; $ user -> setPasswordRequestedAt ( new \ DateTime ( ) ) ; } // Send Resetting Email $ emailBody = [ 'confirmationUrl' => $ this -> generateUrl ( 'security_resetting_password' , [ 'token' => $ user -> getConfirmationToken ( ) ] , UrlGeneratorInterface :: ABSOLUTE_URL ) , ] ; $ this -> sendEmail ( $ user , $ mailer , 'Account Password Resetting' , $ emailBody , 'Resetting' ) ; // Update User $ em -> persist ( $ user ) ; $ em -> flush ( ) ; // Dispatch Register Event if ( $ response = $ dispatcher -> dispatch ( UserEvent :: RESETTING , new UserEvent ( $ user ) ) -> getResponse ( ) ) { return $ response ; } // Render return $ this -> render ( $ this -> getParameter ( 'pd_user.template_path' ) . '/Resetting/resettingSuccess.html.twig' , [ 'sendEmail' => true , ] ) ; } } } // Render return $ this -> render ( $ this -> getParameter ( 'pd_user.template_path' ) . '/Resetting/resetting.html.twig' , [ 'form' => $ form -> createView ( ) , ] ) ; }
Resetting Request.

@param Request $request

@throws \Exception

@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
Resetting Request .