<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use App\Manager\UserManager;
class SecurityController extends AbstractController
{
/**
* @var UserPasswordEncoderInterface
*/
private $passwordEncoder;
public function __construct(UserPasswordEncoderInterface $passwordEncoder)
{
$this->passwordEncoder = $passwordEncoder;
}
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
/**
* @Route("/reset-password/{token}", name="app_reset_password_mail")
*/
public function getResetPassword(Request $request, string $token, UserManager $userManager): Response
{
$inputVariables = $userManager->getInputErrors(['inputErrors']);
return $this->render('security/reset-password.html.twig', [
'token' => $token,
'inputErrors' => $inputVariables['inputErrors'],
]);
}
/**
* @Route("/register", name="app_register")
*/
public function register(Request $request, UserPasswordEncoderInterface $userPasswordEncoder, EntityManagerInterface $entityManager, UserManager $userManager): Response
{
$stripeVariables = $userManager->getStripeErrors(['stripeErrors']);
$inputVariables = $userManager->getInputErrors(['inputErrors']);
$variables = $userManager->getSectorsVariables(['sectors']);
return $this->render('registration/register.html.twig', [
'stripeErrors' => $stripeVariables['stripeErrors'],
'sectors' => $variables['sectors'],
'inputErrors' => $inputVariables['inputErrors'],
]);
}
/**
* @Route("/forgot-password", name="app_forgot_password")
*/
public function forgotPassword(UserManager $userManager): Response
{
$inputVariables = $userManager->getInputErrors(['inputErrors']);
return $this->render('forgot-password/forgot-password.html.twig', [
'controller_name' => 'ForgotPasswordController',
'inputErrors' => $inputVariables['inputErrors'],
]);
}
/**
* @Route("/tmpLogin/{token}", name="app_tmp_login")
*/
public function tmpLogin(Request $request, string $token)
{
$em = $this->getDoctrine()->getManager();
$user = $em->getRepository(User::class)->findOneBy([
'confirmationToken' => $token,
]);
if (is_null($user)) {
return new RedirectResponse($this->container->get('router')->generate('app_login'));
} else {
return new RedirectResponse($this->container->get('router')->generate('app_show_dashboard'));
}
}
}