src/Controller/SecurityController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Form\RecoverPasswordFormType;
  5. use App\Form\ResetPasswordFormType;
  6. use App\Log\SlackLogger;
  7. use App\Service\EmailSender;
  8. use App\Service\FileUploader;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  14. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  15. class SecurityController extends AbstractController
  16. {
  17. /**
  18. * @Route("/login", name="app_login")
  19. * @param AuthenticationUtils $authenticationUtils
  20. * @param SlackLogger $logger
  21. * @return Response
  22. */
  23. public function login(AuthenticationUtils $authenticationUtils, SlackLogger $logger): Response
  24. {
  25. if ($this->isGranted('ROLE_USER')) {
  26. if ($this->isGranted('ROLE_ADMIN')) {
  27. $logger->info("MRS Admin Logged in: " . $this->getUser()->getFullName());
  28. return $this->redirectToRoute('admin_dashboard');
  29. } else {
  30. $logger->info("MRS User Logged in: " . $this->getUser()->getFullName());
  31. return $this->redirectToRoute('dashboard');
  32. }
  33. }
  34. $error = $authenticationUtils->getLastAuthenticationError();
  35. $lastUsername = $authenticationUtils->getLastUsername();
  36. return $this->render('security/login.html.twig', [
  37. 'last_username' => $lastUsername,
  38. 'error' => $error,
  39. 'validation' => !empty($_GET['valid']) ? $_GET['valid'] : false,
  40. 'email' => !empty($_GET['emailMessage']),
  41. ]);
  42. }
  43. /**
  44. * @Route("/file/open", name="app_file_open")
  45. * @param AuthenticationUtils $authenticationUtils
  46. * @param SlackLogger $logger
  47. * @return Response
  48. */
  49. public function fileOpen(Request $request, FileUploader $fileUploader): Response
  50. {
  51. $filename = urldecode($request->get('file'));
  52. $result = $fileUploader->retrieve($filename);
  53. $response = [];
  54. $response['Content-Disposition'] = 'attachment; filename=' . $filename;
  55. return new Response($result['Body'], 200, $response);
  56. }
  57. }