<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\RecoverPasswordFormType;
use App\Form\ResetPasswordFormType;
use App\Log\SlackLogger;
use App\Service\EmailSender;
use App\Service\FileUploader;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login")
* @param AuthenticationUtils $authenticationUtils
* @param SlackLogger $logger
* @return Response
*/
public function login(AuthenticationUtils $authenticationUtils, SlackLogger $logger): Response
{
if ($this->isGranted('ROLE_USER')) {
if ($this->isGranted('ROLE_ADMIN')) {
$logger->info("MRS Admin Logged in: " . $this->getUser()->getFullName());
return $this->redirectToRoute('admin_dashboard');
} else {
$logger->info("MRS User Logged in: " . $this->getUser()->getFullName());
return $this->redirectToRoute('dashboard');
}
}
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'validation' => !empty($_GET['valid']) ? $_GET['valid'] : false,
'email' => !empty($_GET['emailMessage']),
]);
}
/**
* @Route("/file/open", name="app_file_open")
* @param AuthenticationUtils $authenticationUtils
* @param SlackLogger $logger
* @return Response
*/
public function fileOpen(Request $request, FileUploader $fileUploader): Response
{
$filename = urldecode($request->get('file'));
$result = $fileUploader->retrieve($filename);
$response = [];
$response['Content-Disposition'] = 'attachment; filename=' . $filename;
return new Response($result['Body'], 200, $response);
}
}