vendor/uvdesk/core-framework/Controller/Authentication.php line 35

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Controller;
  3. use Symfony\Component\Form\FormError;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
  7. use Symfony\Component\EventDispatcher\GenericEvent;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  10. use Webkul\UVDesk\CoreFrameworkBundle\Utils\TokenGenerator;
  11. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  12. use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;
  13. class Authentication extends Controller
  14. {
  15.     public function login(Request $request)
  16.     {
  17.         if (null == $this->get('user.service')->getSessionUser()) {
  18.             return $this->render('@UVDeskCoreFramework//login.html.twig', [
  19.                 'last_username' => $this->get('security.authentication_utils')->getLastUsername(),
  20.                 'error' => $this->get('security.authentication_utils')->getLastAuthenticationError(),
  21.             ]);
  22.         }
  23.         
  24.         return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  25.     }
  26.     public function logout(Request $request)
  27.     {
  28.         return;
  29.     }
  30.     public function forgotPassword(Request $request)
  31.     {   
  32.         $entityManager $this->getDoctrine()->getManager();
  33.             
  34.         if ($request->getMethod() == 'POST') {
  35.             $user = new User();
  36.             $form $this->createFormBuilder($user,['csrf_protection' => false])
  37.                     ->add('email',EmailType::class)
  38.                     ->getForm();
  39.             $form->submit(['email' => $request->request->get('forgot_password_form')['email']]);
  40.             $form->handleRequest($request);
  41.             
  42.             if ($form->isValid()) {
  43.                 $repository $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User');
  44.                 $user $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($form->getData()->getEmail());
  45.                 if (!empty($user)) {
  46.                     // Trigger agent forgot password event
  47.                     $event = new GenericEvent(CoreWorkflowEvents\UserForgotPassword::getId(), [
  48.                         'entity' => $user,
  49.                     ]);
  50.                         
  51.                     $this->get('event_dispatcher')->dispatch('uvdesk.automation.workflow.execute'$event);
  52.                     $this->addFlash('success'$this->get('translator')->trans('Please check your mail for password update'));
  53.                     return $this->redirect($this->generateUrl('helpdesk_knowledgebase'));
  54.                 } else {
  55.                     $this->addFlash('warning'$this->get('translator')->trans('This email address is not registered with us'));
  56.                 }
  57.             }
  58.         }
  59.             
  60.         return $this->render("@UVDeskCoreFramework//forgotPassword.html.twig");
  61.     }
  62.     public function updateCredentials($email$verificationCodeRequest $requestUserPasswordEncoderInterface $encoder)
  63.     {
  64.         $entityManager $this->getDoctrine()->getManager();
  65.         $user $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($email);
  66.         if (empty($user) || $user->getVerificationCode() != $verificationCode) {
  67.             $this->addFlash('success'$this->get('translator')->trans('You have already update password using this link if you wish to change password again click on forget password link here from login page'));
  68.             return $this->redirect($this->generateUrl('helpdesk_knowledgebase'));
  69.         }
  70.         
  71.         if ($request->getMethod() == 'POST') {
  72.             $updatedCredentials $request->request->all();
  73.             if ($updatedCredentials['password'] === $updatedCredentials['confirmPassword']) {
  74.                 $user->setPassword($encoder->encodePassword($user$updatedCredentials['password']));
  75.                 $user->setVerificationCode(TokenGenerator::generateToken());
  76.                 $entityManager->persist($user);
  77.                 $entityManager->flush();
  78.                 $this->addFlash('success'$this->get('translator')->trans('Your password has been successfully updated. Login using updated password'));
  79.                 return $this->redirect($this->generateUrl('helpdesk_knowledgebase'));
  80.             } else {
  81.                 $this->addFlash('success'$this->get('translator')->trans('Please try again, The passwords do not match'));
  82.             }
  83.         }
  84.         return $this->render("@UVDeskCoreFramework//resetPassword.html.twig");
  85.     }
  86. }