<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use App\Service\Settings;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
class SecurityController extends AbstractController
{
private $files_download_path;
public function __construct(ContainerBagInterface $params,Settings $settings)
{
$this->files_download_path = $params->get('app.files.download.path');
}
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$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("/storage/uploads/{dir}/{file}", name="app_uploads")
*/
public function uploads(string $dir, string $file)
{
if($this->getUser()){
$fp = $this->getParameter('kernel.project_dir').'/'.$this->files_download_path.$dir.'/'.$file;
if(file_exists($fp)){
return new BinaryFileResponse($fp);
}
}
return new Response();
}
/**
* @Route("/storage/uploads/{file}", name="app_single_file")
*/
public function uploadsSingle(string $file)
{
if($this->getUser()){
$fp = $this->getParameter('kernel.project_dir').'/'.$this->files_download_path.'/'.$file;
if(file_exists($fp)){
return new BinaryFileResponse($fp);
}
}
return new Response();
}
}