diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 0d566b9..e0f9268 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -40,8 +40,9 @@ security: access_control: - { path: ^/login, roles: PUBLIC_ACCESS } - { path: ^/register, roles: PUBLIC_ACCESS } - - { path: ^/, roles: ROLE_USER } - { path: ^/admin, roles: ROLE_ADMIN } + - { path: ^/, roles: ROLE_USER } + diff --git a/public/css/admin.css b/public/css/admin.css new file mode 100644 index 0000000..5518441 --- /dev/null +++ b/public/css/admin.css @@ -0,0 +1,90 @@ +body { + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + background-color: #f4f6f8; + color: #333; + margin: 2rem auto; + max-width: 800px; + padding: 1rem; +} + + +h1 { + color: #2c3e50; + font-size: 2rem; + margin-bottom: 1rem; + text-align: center; +} + +h2 { + color: #34495e; + font-size: 1.4rem; + margin-top: 2rem; + margin-bottom: 1rem; + border-bottom: 2px solid #ccc; + padding-bottom: 0.2rem; +} + +section { + background: white; + border-radius: 8px; + padding: 1.5rem; + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); + margin-bottom: 1.5rem; +} + +ul#user-list { + list-style: none; + padding: 0; +} + +#user-list li { + background: #ecf0f1; + margin-bottom: 0.5rem; + padding: 0.8rem 1rem; + border-radius: 6px; + display: flex; + justify-content: space-between; + align-items: center; +} + +#user-list li button { + background-color: #e74c3c; + color: white; + border: none; + padding: 6px 12px; + border-radius: 4px; + cursor: pointer; + font-size: 0.9rem; +} + +#user-list li button:hover { + background-color: #c0392b; +} + +form#add-user-form { + display: flex; + flex-direction: column; + gap: 0.8rem; +} + +form#add-user-form input, +form#add-user-form select { + padding: 0.6rem; + border: 1px solid #bdc3c7; + border-radius: 4px; + font-size: 1rem; +} + +form#add-user-form button { + background-color: #3498db; + color: white; + border: none; + padding: 0.7rem; + border-radius: 4px; + font-size: 1rem; + cursor: pointer; +} + +form#add-user-form button:hover { + background-color: #2980b9; +} diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 0a11a6a..8b59159 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -13,7 +13,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; -#[Route('/admin', name: 'admin_users_')] +#[Route('/admin', name: 'admin_')] #[IsGranted('ROLE_ADMIN')] class AdminController extends AbstractController { @@ -26,7 +26,13 @@ class AdminController extends AbstractController $this->passwordHasher = $passwordHasher; } - #[Route('/users', name: 'list', methods: ['GET'])] + #[Route('', name: 'admin_dashboard')] + public function dashboard(): Response + { + return $this->render('admin/index.html.twig'); + } + + #[Route('/users', name: 'users_list', methods: ['GET'])] public function getUserById(UserRepository $userRepository): JsonResponse { $users = $userRepository->findAll(); @@ -71,4 +77,22 @@ class AdminController extends AbstractController return $this->json(['message' => 'User created successfully', 'id' => $user->getId()], Response::HTTP_CREATED); } + #[Route('/users/delete/{id}', name: 'delete_user', methods: ['DELETE'])] + public function deleteUser(int $id): JsonResponse + { + $user = $this->entityManager->getRepository(User::class)->find($id); + + if (!$user) { + return $this->json(['error' => 'User not found'], Response::HTTP_NOT_FOUND); + } + + foreach ($user->getEmojis() as $userEmoji) { + $this->entityManager->remove($userEmoji); + } + $this->entityManager->remove($user); + $this->entityManager->flush(); + + return $this->json(['message' => 'User and related data deleted successfully'], Response::HTTP_OK); + } + } diff --git a/src/Entity/User.php b/src/Entity/User.php index 99642fe..9ddf1c0 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -38,7 +38,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface public function __construct() { $this->emojis = new ArrayCollection(); - $this->emoji = new ArrayCollection(); } public function getId(): ?int @@ -58,19 +57,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ public function getUserIdentifier(): string { return (string) $this->username; } - /** - * @see UserInterface - */ + public function getRoles(): array { $roles = $this->roles; @@ -87,9 +79,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } - /** - * @see PasswordAuthenticatedUserInterface - */ public function getPassword(): string { return $this->password; @@ -103,9 +92,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface } public function getEmojis(): Collection -{ - return $this->emojis; -} + { + return $this->emojis; + } /** * @see UserInterface @@ -115,34 +104,4 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface // If you store any temporary, sensitive data on the user, clear it here // $this->plainPassword = null; } - - /** - * @return Collection - */ - public function getEmoji(): Collection - { - return $this->emoji; - } - - public function addEmoji(UserEmojis $emoji): static - { - if (!$this->emoji->contains($emoji)) { - $this->emoji->add($emoji); - $emoji->setUser($this); - } - - return $this; - } - - public function removeEmoji(UserEmojis $emoji): static - { - if ($this->emoji->removeElement($emoji)) { - // set the owning side to null (unless already changed) - if ($emoji->getUser() === $this) { - $emoji->setUser(null); - } - } - - return $this; - } } diff --git a/templates/admin/index.html.twig b/templates/admin/index.html.twig new file mode 100644 index 0000000..990c641 --- /dev/null +++ b/templates/admin/index.html.twig @@ -0,0 +1,84 @@ +{% extends 'base.html.twig' %} + +{% block stylesheets %} + +{% endblock %} + +{% block title %}Admin - Gestion des utilisateurs{% endblock %} + +{% block body %} +

🔐 Admin - Gestion des utilisateurs

+ +
+

👥 Liste des utilisateurs

+ +
+ +
+

➕ Ajouter un utilisateur

+
+ + + + +
+
+ + +{% endblock %} diff --git a/templates/home/index.html.twig b/templates/home/index.html.twig index 4235402..0a3971d 100644 --- a/templates/home/index.html.twig +++ b/templates/home/index.html.twig @@ -9,9 +9,9 @@ {% block body %} {% if app.user %}
- Connecté en tant que {{ app.user.username }} + Connecté en tant que {{ app.user.username }}
- +