src/Controller/SecurityController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  8. use App\Service\Settings;
  9. use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
  10. class SecurityController extends AbstractController
  11. {
  12. private $files_download_path;
  13. public function __construct(ContainerBagInterface $params,Settings $settings)
  14. {
  15. $this->files_download_path = $params->get('app.files.download.path');
  16. }
  17. /**
  18. * @Route("/login", name="app_login")
  19. */
  20. public function login(AuthenticationUtils $authenticationUtils): Response
  21. {
  22. // if ($this->getUser()) {
  23. // return $this->redirectToRoute('target_path');
  24. // }
  25. // get the login error if there is one
  26. $error = $authenticationUtils->getLastAuthenticationError();
  27. // last username entered by the user
  28. $lastUsername = $authenticationUtils->getLastUsername();
  29. return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
  30. }
  31. /**
  32. * @Route("/logout", name="app_logout")
  33. */
  34. public function logout()
  35. {
  36. throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  37. }
  38. /**
  39. * @Route("/storage/uploads/{dir}/{file}", name="app_uploads")
  40. */
  41. public function uploads(string $dir, string $file)
  42. {
  43. if($this->getUser()){
  44. $fp = $this->getParameter('kernel.project_dir').'/'.$this->files_download_path.$dir.'/'.$file;
  45. if(file_exists($fp)){
  46. return new BinaryFileResponse($fp);
  47. }
  48. }
  49. return new Response();
  50. }
  51. /**
  52. * @Route("/storage/uploads/{file}", name="app_single_file")
  53. */
  54. public function uploadsSingle(string $file)
  55. {
  56. if($this->getUser()){
  57. $fp = $this->getParameter('kernel.project_dir').'/'.$this->files_download_path.'/'.$file;
  58. if(file_exists($fp)){
  59. return new BinaryFileResponse($fp);
  60. }
  61. }
  62. return new Response();
  63. }
  64. }