| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Kunstmaan\AdminBundle\Controller\Authentication; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Kunstmaan\AdminBundle\Entity\UserInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Kunstmaan\AdminBundle\Form\NewPasswordType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Kunstmaan\AdminBundle\Form\PasswordRequestType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Kunstmaan\AdminBundle\Service\PasswordResetService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Kunstmaan\AdminBundle\Service\UserManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Component\HttpFoundation\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Symfony\Component\Routing\Annotation\Route; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | final class PasswordResetController extends AbstractController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** @var PasswordResetService */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     private $passwordResetService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** @var UserManager */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private $userManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public function __construct(PasswordResetService $passwordResetService, UserManager $userManager) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->passwordResetService = $passwordResetService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->userManager = $userManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @Route("/resetting/request", name="cms_reset_password", methods={"GET", "POST"}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @Route("/resetting/request", name="fos_user_resetting_request", methods={"GET", "POST"}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function resetPasswordAction(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $form = $this->createForm(PasswordRequestType::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $form->handleRequest($request); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         if ($form->isSubmitted() && $form->isValid()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             $this->passwordResetService->processResetRequest($form->get('email')->getData(), $request->getLocale()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             $this->addFlash('success', 'security.resetting.send_email_success'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             return $this->redirectToRoute('cms_reset_password'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         return $this->render('@KunstmaanAdmin/authentication/password_reset/request.html.twig', ['form' => $form->createView()]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @Route("/reset_password/confirm/{token}", name="cms_reset_password_confirm", methods={"GET", "POST"}) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |     public function resetPasswordCheckAction(Request $request, string $token) | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |         /** @var UserInterface|null $user */ | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |         $user = $this->userManager->findUserByConfirmationToken($token); | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |         if (null === $user) { | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |             $this->addFlash('danger', 'security.resetting.user_not_found'); | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |             return $this->redirectToRoute('cms_reset_password'); | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |         $form = $this->createForm(NewPasswordType::class); | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |         $form->handleRequest($request); | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |         if ($form->isSubmitted() && $form->isValid()) { | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |             $response = $this->passwordResetService->resetPassword($user, $form->get('plainPassword')->getData()); | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |             $this->addFlash('success', 'security.resetting.password_set_success'); | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |             return $response; | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |         return $this->render('@KunstmaanAdmin/authentication/password_reset/confirm.twig', ['form' => $form->createView()]); | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |  |