src/UserPanel/Modules/User/Controller/ResettingController.php line 26

  1. <?php
  2. namespace App\UserPanel\Modules\User\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use App\Controller\BaseController;
  6. use App\Modules\User\Entity\User;
  7. use App\UserPanel\Modules\User\Service\UserService;
  8. use App\UserPanel\Modules\User\Form\ResetPasswordType;
  9. use App\UserPanel\Modules\User\Form\ChangePasswordType;
  10. class ResettingController extends BaseController
  11. {
  12.     private $_doctrine;
  13.     private $_userService;
  14.     public function __construct(
  15.             ManagerRegistry $doctrine,
  16.             UserService $userService)
  17.     {
  18.         $this->_doctrine $doctrine;
  19.         $this->_userService $userService;
  20.     }
  21.     
  22.     public function resetPassword(Request $request)
  23.     {
  24.         $form $this->createForm(ResetPasswordType::class);
  25.         $form->handleRequest($request);
  26.         if ($form->isSubmitted())
  27.         {
  28.             if ($form->isValid())
  29.             {
  30.                 $this->_userService->sendResetPasswordRequest($form->getConfig()->getType()->getInnerType()->user);
  31.                 $this->addFlash('success'$this->translate('uzytkownik_wyslano_potwierdzenie_zmiany_hasla'));
  32.                 return $this->redirectToRoute('user_reset_password');
  33.             }
  34.         }
  35.         return $this->render('UserPanel/Modules/User/Templates/Resetting/resetPassword.html.twig', array(
  36.             'form' => $form->createView()
  37.         ));
  38.     }
  39.     
  40.     public function changePassword(Request $request$userId$code)
  41.     {
  42.         $user $this->_doctrine->getRepository(User::class)->findOneBy(['id' => $userId'type' => User::TYPE_CLIENT'isActive' => true]);
  43.         
  44.         if (!$user || !$this->_userService->isVerificationCodeValid($user$code))
  45.             $this->throwError400Exception();
  46.         
  47.         $form $this->createForm(ChangePasswordType::class);
  48.         $form->handleRequest($request);        
  49.         if ($form->isSubmitted())
  50.         {
  51.             if ($form->isValid())
  52.             {
  53.                 $this->_userService->changePassword($user$form['password']->getData());
  54.                 return $this->redirectToRoute('user_panel_user_password_changed');
  55.             }
  56.         }
  57.         return $this->render('UserPanel/Modules/User/Templates/Resetting/changePassword.html.twig', array(
  58.             'form' => $form->createView()
  59.         ));
  60.     }
  61.     
  62.     public function passwordChanged()
  63.     {
  64.         return $this->render('UserPanel/Modules/User/Templates/Resetting/passwordChanged.html.twig');
  65.     }    
  66. }