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 %} +
+ +
+ +
+ + +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+ + + +
+ +

An Error Occurred

+

The server encountered an unexpected error.

+
+
+ +
+
+
+
+{% endblock %} diff --git a/templates/bundles/TwigBundle/Exception/error404.html.twig b/templates/bundles/TwigBundle/Exception/error404.html.twig new file mode 100644 index 0000000..181d533 --- /dev/null +++ b/templates/bundles/TwigBundle/Exception/error404.html.twig @@ -0,0 +1,42 @@ +{% extends 'base.html.twig' %} + +{% block title %}Page Not Found{% endblock %} + +{% block body %} +
+ +
+ +
+ + +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+ + + +
+ +

Page Not Found

+

The page you are looking for does not exist.

+
+
+ +
+
+
+
+{% endblock %} diff --git a/templates/poll/show.html.twig b/templates/poll/show.html.twig index d0fbde1..a7627ad 100644 --- a/templates/poll/show.html.twig +++ b/templates/poll/show.html.twig @@ -27,9 +27,11 @@ {{ form_start(form) }}
{% for child in form.choice %} -
diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig index 670fc74..0777e18 100644 --- a/templates/security/login.html.twig +++ b/templates/security/login.html.twig @@ -38,6 +38,13 @@ +
+ +
+