diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 0ecece0..bece817 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -14,8 +14,11 @@ security: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false + main: anonymous: ~ + pattern: ^/ + user_checker: App\Security\UserChecker guard: authenticators: - App\Security\LoginFormAuthentificatorAuthenticator diff --git a/config/routes.yaml b/config/routes.yaml index 9ebc1bb..3e96df1 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -16,4 +16,9 @@ registerForm: register: path: /register controller: App\Controller\SecurityController::register - methods: POST \ No newline at end of file + methods: POST + +users: + path: /users + controller: App\Controller\SecurityController::showUserManagePage + methods: GET \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index baa4e4c..48810ea 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -5,7 +5,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; - +use App\Service\Menus; use Doctrine\ORM\EntityManagerInterface; @@ -14,9 +14,11 @@ Class HomeController extends AbstractController { public function index(){ $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); - return new Response( - "Hey" - ); + + $menus = new Menus(); + return $this->render('main.html.twig', [ + "menus" => $menus->getMenus( $this->getUser() ) + ]); } } \ No newline at end of file diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 3159bfb..e0766d4 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -68,7 +68,6 @@ class SecurityController extends AbstractController { $form = $this->getRegisterForm(); $form->handleRequest($request); - echo "hey"; if ($form->isSubmitted() && $form->isValid()) { $data = $form->getData(); @@ -94,4 +93,9 @@ class SecurityController extends AbstractController } + public function showUserManagePage() + { + + } + } diff --git a/src/Entity/User.php b/src/Entity/User.php index f3f2077..c5c8dab 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -70,6 +70,11 @@ class User implements UserInterface return (string) $this->email; } + public function isGranted($role): bool + { + return in_array($role, $this->getRoles()); + } + /** * @see UserInterface */ diff --git a/src/Security/UserChecker.php b/src/Security/UserChecker.php new file mode 100644 index 0000000..a146b9a --- /dev/null +++ b/src/Security/UserChecker.php @@ -0,0 +1,36 @@ + getActive() === false) { + throw new AccountDeletedException(); + } + } + + public function checkPostAuth(UserInterface $user) + { + if (!$user instanceof AppUser) { + return; + } + + // user is not activated + if ($user->getActive() === false) { + throw new AccountDeletedException(); + } + } +} \ No newline at end of file diff --git a/src/Service/Menus.php b/src/Service/Menus.php new file mode 100644 index 0000000..1fc7fd7 --- /dev/null +++ b/src/Service/Menus.php @@ -0,0 +1,34 @@ + "app_logout", + "title" => "log out" + ), + ); + + + if( $user->isGranted('SUPER_ADMIN') ) + { + $menus[] = array( + "route" => "users", + "title" => "Users" + ); + } + + + + return $menus; + } + +} \ No newline at end of file diff --git a/templates/base.html.twig b/templates/base.html.twig index 66b1425..16c9b21 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -10,10 +10,10 @@