diff --git a/config/packages/security.yaml b/config/packages/security.yaml index b69f6b5..b85edc6 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -21,6 +21,12 @@ security: check_path: app_login enable_csrf: true default_target_path: app_admin_index + remember_me: + secret: '%kernel.secret%' + # 6 months in seconds + lifetime: 15552000 + path: / + always_remember_me: true logout: path: app_logout # where to redirect after logout diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index e1aa9d3..8403c26 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -32,8 +32,14 @@ public function index(): Response } #[Route('/show/{id}', name: 'show')] - public function show(Poll $poll): Response + public function show(?Poll $poll = null): Response { + if (null === $poll) { + $this->addFlash(FlashTypeEnum::ERROR->value, 'This poll does not exist.'); + + return $this->redirectToRoute('app_admin_index'); + } + return $this->render('admin/show.html.twig', [ 'poll' => $poll, ]); @@ -54,8 +60,14 @@ public function create(Request $request): Response } #[Route('/edit/{id}', name: 'edit')] - public function edit(Request $request, Poll $poll): Response + public function edit(Request $request, ?Poll $poll = null): Response { + if (null === $poll) { + $this->addFlash(FlashTypeEnum::ERROR->value, 'This poll does not exist.'); + + return $this->redirectToRoute('app_admin_index'); + } + if ($this->pollService->checkIfPollHasVotes($poll)) { $this->addFlash(FlashTypeEnum::ERROR->value, 'This poll has votes and cannot be edited.'); diff --git a/templates/bundles/TwigBundle/Exception/error.html.twig b/templates/bundles/TwigBundle/Exception/error.html.twig new file mode 100644 index 0000000..cf07bcf --- /dev/null +++ b/templates/bundles/TwigBundle/Exception/error.html.twig @@ -0,0 +1,42 @@ +{% extends 'base.html.twig' %} + +{% block title %}An Error Occurred{% endblock %} + +{% block body %} +
The server encountered an unexpected error.
+The page you are looking for does not exist.
+