diff --git a/public/css/admin.css b/public/css/admin.css new file mode 100644 index 0000000..a89bb63 --- /dev/null +++ b/public/css/admin.css @@ -0,0 +1,10 @@ +.customChip { + display: inline-block; + background-color: darkred; + font-size: 1vw; + padding: 0 5% 0 5%; + height: 1.5vw; + border-radius: 0.75vw; + font-weight: bold; + color: lightgrey; +} \ No newline at end of file diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php new file mode 100644 index 0000000..7ea8682 --- /dev/null +++ b/src/Controller/UserController.php @@ -0,0 +1,39 @@ +userService = $userService; + } + + /** + * @Route("/admin/users", name="app_user_list") + */ + public function userList(): Response + { + if (!$this->isGranted("ROLE_ADMIN")) { + // not logged in + throw new AccessDeniedHttpException(); + } + + $users = $this->userService->getUsers(); + + return $this->render("user/users.html.twig", [ + "users" => $users + ]); + } +} \ No newline at end of file diff --git a/src/DataFixtures/UserFixtures.php b/src/DataFixtures/UserFixtures.php index b73fa67..6fadb07 100644 --- a/src/DataFixtures/UserFixtures.php +++ b/src/DataFixtures/UserFixtures.php @@ -24,6 +24,7 @@ class UserFixtures extends Fixture $admin = new User(); $admin->setName("admin"); $admin->setPassword($this->passwordEncoder->encodePassword($admin, "password")); + $admin->setRoles(["ROLE_ADMIN"]); $manager->persist($admin); $manager->flush(); diff --git a/src/Entity/User.php b/src/Entity/User.php index d968460..98a4766 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -156,4 +156,16 @@ class User implements UserInterface return $this; } + + public function getReadableRoles(): array + { + return array_map(function ($role) { + $i = strrpos($role, "_"); + if ($i) { + // $i === false it's probably a custom name + return substr($role, $i + 1); + } + return $role; + }, $this->getRoles()); + } } diff --git a/src/Service/UserService.php b/src/Service/UserService.php index 20b0278..48c0968 100644 --- a/src/Service/UserService.php +++ b/src/Service/UserService.php @@ -31,4 +31,9 @@ class UserService return $user; } + + public function getUsers(): array + { + return $this->userRepository->findAll(); + } } \ No newline at end of file diff --git a/templates/base.html.twig b/templates/base.html.twig index 5217992..95bdf0b 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -33,18 +33,29 @@