Skip to content

Commit

Permalink
👌 IMPROVE: Added the "Remember Me" feature and error handling for non…
Browse files Browse the repository at this point in the history
…-existent surveys
  • Loading branch information
yoanbernabeu committed Dec 22, 2024
1 parent ef287ac commit 8b83705
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 5 deletions.
6 changes: 6 additions & 0 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand All @@ -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.');

Expand Down
42 changes: 42 additions & 0 deletions templates/bundles/TwigBundle/Exception/error.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% extends 'base.html.twig' %}

{% block title %}An Error Occurred{% endblock %}

{% block body %}
<div class="min-h-screen bg-[#0a0a0a] grid place-items-center relative">
<!-- Background Effects -->
<div class="absolute inset-0 z-0">
<!-- Dark Gradient Base -->
<div class="absolute inset-0 bg-gradient-to-br from-black via-base-300 to-black opacity-90"></div>

<!-- Animated Gradient Effects -->
<div class="absolute inset-0">
<div class="absolute top-0 left-1/4 w-[500px] h-[500px] bg-red-600/20 rounded-full blur-[100px] animate-pulse"></div>
<div class="absolute bottom-0 right-1/4 w-[500px] h-[500px] bg-orange-600/20 rounded-full blur-[100px] animate-pulse delay-1000"></div>
<div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[800px] h-[800px] bg-red-600/10 rounded-full blur-[120px] animate-pulse delay-700"></div>
</div>
</div>

<div class="max-w-md w-full px-4 relative z-10">
<div class="relative group">
<div class="absolute -inset-1 bg-gradient-to-r from-error via-orange-500 to-red-500 opacity-75 blur-xl group-hover:opacity-100 transition duration-1000"></div>
<div class="absolute -inset-2 bg-gradient-to-r from-error via-orange-500 to-red-500 opacity-50 blur-2xl group-hover:opacity-75 transition duration-1000 animate-pulse"></div>

<div class="card bg-base-100 shadow-xl relative">
<div class="card-body items-center text-center">
<div class="text-error mb-4">
<svg xmlns="http://www.w3.org/2000/svg" class="w-24 h-24" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
</div>

<h1 class="text-3xl font-bold mb-4">An Error Occurred</h1>
<p class="text-base-content/70 mb-8">The server encountered an unexpected error.</p>
</div>
</div>

<div class="absolute inset-0 rounded-lg ring-2 ring-error/20 z-20"></div>
</div>
</div>
</div>
{% endblock %}
42 changes: 42 additions & 0 deletions templates/bundles/TwigBundle/Exception/error404.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{% extends 'base.html.twig' %}

{% block title %}Page Not Found{% endblock %}

{% block body %}
<div class="min-h-screen bg-[#0a0a0a] grid place-items-center relative">
<!-- Background Effects -->
<div class="absolute inset-0 z-0">
<!-- Dark Gradient Base -->
<div class="absolute inset-0 bg-gradient-to-br from-black via-base-300 to-black opacity-90"></div>

<!-- Animated Gradient Effects -->
<div class="absolute inset-0">
<div class="absolute top-0 left-1/4 w-[500px] h-[500px] bg-red-600/20 rounded-full blur-[100px] animate-pulse"></div>
<div class="absolute bottom-0 right-1/4 w-[500px] h-[500px] bg-orange-600/20 rounded-full blur-[100px] animate-pulse delay-1000"></div>
<div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[800px] h-[800px] bg-red-600/10 rounded-full blur-[120px] animate-pulse delay-700"></div>
</div>
</div>

<div class="max-w-md w-full px-4 relative z-10">
<div class="relative group">
<div class="absolute -inset-1 bg-gradient-to-r from-error via-orange-500 to-red-500 opacity-75 blur-xl group-hover:opacity-100 transition duration-1000"></div>
<div class="absolute -inset-2 bg-gradient-to-r from-error via-orange-500 to-red-500 opacity-50 blur-2xl group-hover:opacity-75 transition duration-1000 animate-pulse"></div>

<div class="card bg-base-100 shadow-xl relative">
<div class="card-body items-center text-center">
<div class="text-error mb-4">
<svg xmlns="http://www.w3.org/2000/svg" class="w-24 h-24" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
</div>

<h1 class="text-3xl font-bold mb-4">Page Not Found</h1>
<p class="text-base-content/70 mb-8">The page you are looking for does not exist.</p>
</div>
</div>

<div class="absolute inset-0 rounded-lg ring-2 ring-error/20 z-20"></div>
</div>
</div>
</div>
{% endblock %}
8 changes: 5 additions & 3 deletions templates/poll/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
{{ form_start(form) }}
<div class="flex flex-col gap-2">
{% for child in form.choice %}
<label class="flex items-center gap-2 btn btn-outline h-auto py-4 px-6 cursor-pointer hover:scale-[1.01] transition-transform">
{{ form_widget(child, {'attr': {'class': 'radio radio-primary'}}) }}
<span class="text-lg">{{ child.vars.label }}</span>
<label class="flex items-start btn btn-outline h-auto py-4 px-6 cursor-pointer hover:scale-[1.01] transition-transform">
<div class="flex items-start gap-4 w-full">
{{ form_widget(child, {'attr': {'class': 'radio radio-primary mt-1.5'}}) }}
<span class="text-lg text-left flex-1">{{ child.vars.label }}</span>
</div>
</label>
{% endfor %}
</div>
Expand Down
7 changes: 7 additions & 0 deletions templates/security/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@

<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">

<div class="form-control">
<label class="label cursor-pointer">
<span class="label-text">Remember me</span>
<input type="checkbox" name="_remember_me" class="checkbox checkbox-primary">
</label>
</div>

<div class="mt-6">
<button class="btn btn-primary w-full" type="submit">
Sign in
Expand Down

0 comments on commit 8b83705

Please sign in to comment.