@@ -7,16 +7,16 @@ |
||
| 7 | 7 | |
| 8 | 8 | class DefaultController extends Controller |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @Route("/index", name="ribsadmin_index") |
|
| 12 | - * @Route("/accounts", name="ribsadmin_accounts") |
|
| 13 | - * @Route("/access-rights-management", name="ribsadmin_access_rights") |
|
| 14 | - * @Route("/contents", name="ribsadmin_contents") |
|
| 15 | - * @Route("/navigation", name="ribsadmin_navigation") |
|
| 16 | - * |
|
| 17 | - */ |
|
| 18 | - public function indexAction() |
|
| 19 | - { |
|
| 20 | - return $this->render('RibsAdminBundle:Default:index.html.twig'); |
|
| 21 | - } |
|
| 10 | + /** |
|
| 11 | + * @Route("/index", name="ribsadmin_index") |
|
| 12 | + * @Route("/accounts", name="ribsadmin_accounts") |
|
| 13 | + * @Route("/access-rights-management", name="ribsadmin_access_rights") |
|
| 14 | + * @Route("/contents", name="ribsadmin_contents") |
|
| 15 | + * @Route("/navigation", name="ribsadmin_navigation") |
|
| 16 | + * |
|
| 17 | + */ |
|
| 18 | + public function indexAction() |
|
| 19 | + { |
|
| 20 | + return $this->render('RibsAdminBundle:Default:index.html.twig'); |
|
| 21 | + } |
|
| 22 | 22 | } |
@@ -5,8 +5,7 @@ discard block |
||
| 5 | 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
| 6 | 6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
| 7 | 7 | |
| 8 | -class DefaultController extends Controller |
|
| 9 | -{ |
|
| 8 | +class DefaultController extends Controller { |
|
| 10 | 9 | /** |
| 11 | 10 | * @Route("/index", name="ribsadmin_index") |
| 12 | 11 | * @Route("/accounts", name="ribsadmin_accounts") |
@@ -15,8 +14,7 @@ discard block |
||
| 15 | 14 | * @Route("/navigation", name="ribsadmin_navigation") |
| 16 | 15 | * |
| 17 | 16 | */ |
| 18 | - public function indexAction() |
|
| 19 | - { |
|
| 17 | + public function indexAction() { |
|
| 20 | 18 | return $this->render('RibsAdminBundle:Default:index.html.twig'); |
| 21 | 19 | } |
| 22 | 20 | } |
@@ -8,8 +8,7 @@ discard block |
||
| 8 | 8 | use Symfony\Component\Routing\RouterInterface; |
| 9 | 9 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
| 10 | 10 | |
| 11 | -class AccessRights |
|
| 12 | -{ |
|
| 11 | +class AccessRights { |
|
| 13 | 12 | private $em; |
| 14 | 13 | private $router; |
| 15 | 14 | private $session; |
@@ -22,16 +21,14 @@ discard block |
||
| 22 | 21 | * @param Session $session |
| 23 | 22 | * @param RequestStack $request |
| 24 | 23 | */ |
| 25 | - public function __construct(ContainerInterface $em, RouterInterface $router, Session $session, RequestStack $request) |
|
| 26 | - { |
|
| 24 | + public function __construct(ContainerInterface $em, RouterInterface $router, Session $session, RequestStack $request) { |
|
| 27 | 25 | $this->em = $em; |
| 28 | 26 | $this->router = $router; |
| 29 | 27 | $this->session = $session; |
| 30 | 28 | $this->request = $request; |
| 31 | 29 | } |
| 32 | 30 | |
| 33 | - public function onKernelController() |
|
| 34 | - { |
|
| 31 | + public function onKernelController() { |
|
| 35 | 32 | $route = $this->request->getCurrentRequest()->get("_route"); |
| 36 | 33 | $admin_page = explode("_", $route)[0]; |
| 37 | 34 | |
@@ -72,8 +69,7 @@ discard block |
||
| 72 | 69 | * @return bool|mixed |
| 73 | 70 | * fonction that search if the right contain an url or more |
| 74 | 71 | */ |
| 75 | - private function in_array_recursive($needle, $haystack) |
|
| 76 | - { |
|
| 72 | + private function in_array_recursive($needle, $haystack) { |
|
| 77 | 73 | $rights = []; |
| 78 | 74 | $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($haystack)); |
| 79 | 75 | |
@@ -10,114 +10,114 @@ |
||
| 10 | 10 | |
| 11 | 11 | class AccessRights |
| 12 | 12 | { |
| 13 | - private $em; |
|
| 14 | - private $router; |
|
| 15 | - private $session; |
|
| 16 | - private $request; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * AccessRights constructor. |
|
| 20 | - * @param ContainerInterface $em |
|
| 21 | - * @param RouterInterface $router |
|
| 22 | - * @param Session $session |
|
| 23 | - * @param RequestStack $request |
|
| 24 | - */ |
|
| 25 | - public function __construct(ContainerInterface $em, RouterInterface $router, Session $session, RequestStack $request) |
|
| 26 | - { |
|
| 27 | - $this->em = $em; |
|
| 28 | - $this->router = $router; |
|
| 29 | - $this->session = $session; |
|
| 30 | - $this->request = $request; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function onKernelController() |
|
| 34 | - { |
|
| 35 | - $route = $this->request->getCurrentRequest()->get("_route"); |
|
| 36 | - $admin_page = explode("_", $route)[0]; |
|
| 37 | - |
|
| 38 | - //comment because it cause errore redirect |
|
| 39 | - /*if ($route == "fos_user_security_login" || $route == "fos_user_registration_register") { |
|
| 13 | + private $em; |
|
| 14 | + private $router; |
|
| 15 | + private $session; |
|
| 16 | + private $request; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * AccessRights constructor. |
|
| 20 | + * @param ContainerInterface $em |
|
| 21 | + * @param RouterInterface $router |
|
| 22 | + * @param Session $session |
|
| 23 | + * @param RequestStack $request |
|
| 24 | + */ |
|
| 25 | + public function __construct(ContainerInterface $em, RouterInterface $router, Session $session, RequestStack $request) |
|
| 26 | + { |
|
| 27 | + $this->em = $em; |
|
| 28 | + $this->router = $router; |
|
| 29 | + $this->session = $session; |
|
| 30 | + $this->request = $request; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function onKernelController() |
|
| 34 | + { |
|
| 35 | + $route = $this->request->getCurrentRequest()->get("_route"); |
|
| 36 | + $admin_page = explode("_", $route)[0]; |
|
| 37 | + |
|
| 38 | + //comment because it cause errore redirect |
|
| 39 | + /*if ($route == "fos_user_security_login" || $route == "fos_user_registration_register") { |
|
| 40 | 40 | $this->session->clear(); |
| 41 | 41 | $this->em->get("security.token_storage")->setToken(null); |
| 42 | 42 | }*/ |
| 43 | 43 | |
| 44 | - //to show admin panel |
|
| 45 | - if (in_array($route, ["_profiler", "_profiler_search_bar", "_wdt"])) { |
|
| 46 | - return; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $ribs_admin_rights = json_decode(file_get_contents($this->em->get('kernel')->getRootDir() . "/../src/Ribs/RibsAdminBundle/Resources/json/ribsadmin_rights.json")); |
|
| 50 | - |
|
| 51 | - if ($admin_page == "ribsadmin" && ($route !== 404) && ($route !== null)) { |
|
| 52 | - $route_right = $this->in_array_recursive($route, $ribs_admin_rights); |
|
| 53 | - $user_rights = $this->getUserRights(); |
|
| 54 | - |
|
| 55 | - if ($route_right === false) { |
|
| 56 | - throw new AccessDeniedException("No access"); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - foreach ($user_rights as $right) { |
|
| 60 | - if (in_array($right, $route_right)) { |
|
| 61 | - return; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - throw new AccessDeniedException("No access"); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param $needle |
|
| 71 | - * @param $haystack |
|
| 72 | - * @return bool|mixed |
|
| 73 | - * fonction that search if the right contain an url or more |
|
| 74 | - */ |
|
| 75 | - private function in_array_recursive($needle, $haystack) |
|
| 76 | - { |
|
| 77 | - $rights = []; |
|
| 78 | - $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($haystack)); |
|
| 79 | - |
|
| 80 | - foreach ($it AS $element => $value) { |
|
| 81 | - if ($value == $needle) { |
|
| 82 | - $rights[] = $it->getInnerIterator()["right"]; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if (count($rights) === 0) { |
|
| 87 | - return false; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return $rights; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return array function that retun a array that contain all user rights or empty array if no right found |
|
| 96 | - */ |
|
| 97 | - private function getUserRights(): array |
|
| 98 | - { |
|
| 99 | - $user_rights = $this->em->get("security.token_storage")->getToken()->getUser()->getUser()->getAccessRights(); |
|
| 100 | - |
|
| 101 | - if ($user_rights) { |
|
| 102 | - return explode(",", $user_rights); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return [""]; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param string $right |
|
| 110 | - * @return bool |
|
| 111 | - * function that allow to test a right directly in the view |
|
| 112 | - */ |
|
| 113 | - public function testRight(string $right): bool |
|
| 114 | - { |
|
| 115 | - $user_rights = $this->getUserRights(); |
|
| 116 | - |
|
| 117 | - if (in_array($right, $user_rights)) { |
|
| 118 | - return true; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return false; |
|
| 122 | - } |
|
| 44 | + //to show admin panel |
|
| 45 | + if (in_array($route, ["_profiler", "_profiler_search_bar", "_wdt"])) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $ribs_admin_rights = json_decode(file_get_contents($this->em->get('kernel')->getRootDir() . "/../src/Ribs/RibsAdminBundle/Resources/json/ribsadmin_rights.json")); |
|
| 50 | + |
|
| 51 | + if ($admin_page == "ribsadmin" && ($route !== 404) && ($route !== null)) { |
|
| 52 | + $route_right = $this->in_array_recursive($route, $ribs_admin_rights); |
|
| 53 | + $user_rights = $this->getUserRights(); |
|
| 54 | + |
|
| 55 | + if ($route_right === false) { |
|
| 56 | + throw new AccessDeniedException("No access"); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + foreach ($user_rights as $right) { |
|
| 60 | + if (in_array($right, $route_right)) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + throw new AccessDeniedException("No access"); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param $needle |
|
| 71 | + * @param $haystack |
|
| 72 | + * @return bool|mixed |
|
| 73 | + * fonction that search if the right contain an url or more |
|
| 74 | + */ |
|
| 75 | + private function in_array_recursive($needle, $haystack) |
|
| 76 | + { |
|
| 77 | + $rights = []; |
|
| 78 | + $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($haystack)); |
|
| 79 | + |
|
| 80 | + foreach ($it AS $element => $value) { |
|
| 81 | + if ($value == $needle) { |
|
| 82 | + $rights[] = $it->getInnerIterator()["right"]; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if (count($rights) === 0) { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return $rights; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return array function that retun a array that contain all user rights or empty array if no right found |
|
| 96 | + */ |
|
| 97 | + private function getUserRights(): array |
|
| 98 | + { |
|
| 99 | + $user_rights = $this->em->get("security.token_storage")->getToken()->getUser()->getUser()->getAccessRights(); |
|
| 100 | + |
|
| 101 | + if ($user_rights) { |
|
| 102 | + return explode(",", $user_rights); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return [""]; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param string $right |
|
| 110 | + * @return bool |
|
| 111 | + * function that allow to test a right directly in the view |
|
| 112 | + */ |
|
| 113 | + public function testRight(string $right): bool |
|
| 114 | + { |
|
| 115 | + $user_rights = $this->getUserRights(); |
|
| 116 | + |
|
| 117 | + if (in_array($right, $user_rights)) { |
|
| 118 | + return true; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 123 | 123 | } |
| 124 | 124 | \ No newline at end of file |