src/Controller/UsersManagementBundle/DefaultController.php line 89

Open in your IDE?
  1. <?php
  2. namespace App\Controller\UsersManagementBundle;
  3. use App\Entity\LogBundle\DailyCapacityLog;
  4. use App\Entity\UsersManagementBundle\Role;
  5. use App\Controller\UtilityBundle\MyBaseController;
  6. use App\Factory\Logs\DailyCapacityLogFactory;
  7. use App\Services\Helpers\UserHelper;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use App\Entity\UsersManagementBundle\User;
  13. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  14. class DefaultController extends MyBaseController
  15. {
  16.     /**
  17.      * @Route("/", name="AffiliateLogin_BasedOnHostPath" , host="affiliate.mylandcrm.com")
  18.      */
  19.     public function affiliateLoginBasedOnHostAction(Request $request)
  20.     {
  21.         return $this->redirectToRoute('AffiliateLogin_Path');
  22.     }
  23.     /**
  24.      * @Route("/", name="OperatorLogin_BasedOnHostPath" , host="call.mylandcrm.com")
  25.      */
  26.     public function operatorLoginBasedOnHostAction(Request $request)
  27.     {
  28.         return $this->redirectToRoute('OperatorLogin_Path');
  29.     }
  30.     /**
  31.      * @Route("/login", name="Login_Path")
  32.      *
  33.      */
  34.     public function loginAction(AuthenticationUtils $authenticationUtils): Response
  35.     {
  36.         if ($this->getUser())
  37.             return $this->redirectToRoute('Dashboard_Path');
  38.         // get the login error if there is one
  39.         $error $authenticationUtils->getLastAuthenticationError();
  40.         // last username entered by the user
  41.         $lastUsername $authenticationUtils->getLastUsername();
  42.         return $this->render('UsersManagementBundle/Default/login.html.twig',
  43.             array('last_username' => $lastUsername'error' => $error));
  44.     }
  45.     /**
  46.      * @Route("/", name="Login_Path2")
  47.      *
  48.      * check the request and the session if all pass then will show form(login) and will submit to same
  49.      */
  50.     public function login2Action(Request $request)
  51.     {
  52.         //User already logged in
  53.         $auth_checker $this->get('security.authorization_checker');
  54.         $access1 $auth_checker->isGranted('IS_AUTHENTICATED_REMEMBERED');
  55.         $access2 $auth_checker->isGranted('IS_AUTHENTICATED_FULLY');
  56.         if($access1 || $access2)
  57.             return $this->redirectToRoute('Dashboard_Path');
  58.         else
  59.             return $this->redirectToRoute('Login_Path');
  60.     }
  61.     /**
  62.      * @Route("/logout", name="Logout_Path")
  63.      */
  64.     public function logoutAction()
  65.     {
  66.     }
  67.     /**
  68.      * @Route("/forgot-password", name="ForgotPassword_Path")
  69.      */
  70.     public function forgotMyPasswordAction(Request $requestUserPasswordHasherInterface $passwordHasher)
  71.     {
  72.         $params $request->request->all();
  73.         //No Email or No UserName
  74.         if(!isset($params['email']) || $params['email'] == NULL || !isset($params['username']) || $params['username'] == NULL )
  75.             return $this->render('UsersManagementBundle/Default/forgotPassword.html.twig');
  76.         //Email + UserName Found
  77.         
  78.         $user $this->em->getRepository(User::class)->findOneBy(array('email' => $params['email'] , 'username' => $params['username']));
  79.         if(!$user)
  80.         {
  81.             return $this->render('UsersManagementBundle/Default/passwordSentSuccessfully.html.twig');
  82.         }
  83.         else
  84.         {
  85.             //Change password
  86.             $plainTextPassword _generateHash($user->getId());
  87.             $password $passwordHasher->hashPassword($user $plainTextPassword);
  88.             $user->setPassword($password);
  89.             $this->em->persist($user);
  90.             $this->em->flush();
  91.             //Send Email
  92.             $this->myMailer->sendEmail(['subject' => "Password Recovery" ,
  93.                 "template" => 'UtilityBundle/Emails/forgotPassword.html.twig' ,
  94.                 "variables" => array('userName' => $user->getUsername() , 'password' => $plainTextPassword) ,
  95.                 "to" => [$params['email']]]);
  96.             return $this->render('UsersManagementBundle/Default/passwordSentSuccessfully.html.twig');
  97.         }
  98.     }
  99. }