<?php
namespace App\Controller\UsersManagementBundle;
use App\Entity\LogBundle\DailyCapacityLog;
use App\Entity\UsersManagementBundle\Role;
use App\Controller\UtilityBundle\MyBaseController;
use App\Factory\Logs\DailyCapacityLogFactory;
use App\Services\Helpers\UserHelper;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\UsersManagementBundle\User;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class DefaultController extends MyBaseController
{
/**
* @Route("/", name="AffiliateLogin_BasedOnHostPath" , host="affiliate.mylandcrm.com")
*/
public function affiliateLoginBasedOnHostAction(Request $request)
{
return $this->redirectToRoute('AffiliateLogin_Path');
}
/**
* @Route("/", name="OperatorLogin_BasedOnHostPath" , host="call.mylandcrm.com")
*/
public function operatorLoginBasedOnHostAction(Request $request)
{
return $this->redirectToRoute('OperatorLogin_Path');
}
/**
* @Route("/login", name="Login_Path")
*
*/
public function loginAction(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser())
return $this->redirectToRoute('Dashboard_Path');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('UsersManagementBundle/Default/login.html.twig',
array('last_username' => $lastUsername, 'error' => $error));
}
/**
* @Route("/", name="Login_Path2")
*
* check the request and the session if all pass then will show form(login) and will submit to same
*/
public function login2Action(Request $request)
{
//User already logged in
$auth_checker = $this->get('security.authorization_checker');
$access1 = $auth_checker->isGranted('IS_AUTHENTICATED_REMEMBERED');
$access2 = $auth_checker->isGranted('IS_AUTHENTICATED_FULLY');
if($access1 || $access2)
return $this->redirectToRoute('Dashboard_Path');
else
return $this->redirectToRoute('Login_Path');
}
/**
* @Route("/logout", name="Logout_Path")
*/
public function logoutAction()
{
}
/**
* @Route("/forgot-password", name="ForgotPassword_Path")
*/
public function forgotMyPasswordAction(Request $request, UserPasswordHasherInterface $passwordHasher)
{
$params = $request->request->all();
//No Email or No UserName
if(!isset($params['email']) || $params['email'] == NULL || !isset($params['username']) || $params['username'] == NULL )
return $this->render('UsersManagementBundle/Default/forgotPassword.html.twig');
//Email + UserName Found
$user = $this->em->getRepository(User::class)->findOneBy(array('email' => $params['email'] , 'username' => $params['username']));
if(!$user)
{
return $this->render('UsersManagementBundle/Default/passwordSentSuccessfully.html.twig');
}
else
{
//Change password
$plainTextPassword = _generateHash($user->getId());
$password = $passwordHasher->hashPassword($user , $plainTextPassword);
$user->setPassword($password);
$this->em->persist($user);
$this->em->flush();
//Send Email
$this->myMailer->sendEmail(['subject' => "Password Recovery" ,
"template" => 'UtilityBundle/Emails/forgotPassword.html.twig' ,
"variables" => array('userName' => $user->getUsername() , 'password' => $plainTextPassword) ,
"to" => [$params['email']]]);
return $this->render('UsersManagementBundle/Default/passwordSentSuccessfully.html.twig');
}
}
}