Example #1
0
 /**
  * @param Route $route
  * @throws PlinthException
  */
 public function isRouteAuthorized(Route $route)
 {
     $loginpage = $this->main->getSetting('loginpage');
     if (!$route->isPublic()) {
         if (!$this->main->getUserService()->isSessionValid()) {
             if ($route->getName() === $loginpage) {
                 throw new PlinthException('Please set your login page to public');
             }
             $this->disableAction();
             $this->main->getRouter()->redirect($loginpage);
             $this->main->handleRequest(true);
         } else {
             if ($route->hasRoles()) {
                 $roles = $this->main->getUserService()->getUser()->getRouteRoles();
                 if (!is_array($roles)) {
                     throw new PlinthException('The route roles for a user needs to return a array of scalar values.');
                 }
                 if (!$this->main->getRouter()->isUserRoleAllowed($roles)) {
                     $this->main->getResponse()->hardExit(Response::CODE_403);
                 }
             }
         }
     }
 }