Пример #1
0
 function handle(Request $request, AccessDeniedException $accessDeniedException)
 {
     // todo: CUSTOM LOG THIS EVENT!
     /** @var UsernamePasswordToken $token */
     $token = $this->token_storage->getToken();
     $anyAdminRoles = false;
     foreach ($token->getRoles() as $role) {
         /** @var Role $role */
         if (stripos($role->getRole(), '_ADMIN') !== false) {
             $anyAdminRoles = true;
             break;
         }
     }
     if ($accessDeniedException->getCode() == 403 && stripos($request->getPathInfo(), '/admin') !== false) {
         if (!$anyAdminRoles) {
             $content = $this->twig->render('admin/exception/error403.html.twig', array('accessDeniedMessage' => 'You are not authorized to access the Fraternity of Light Admin'));
         } else {
             $content = $this->twig->render('admin/adminindex.html.twig', array('accessDeniedMessage' => 'You do not have permission to view the requested resource'));
         }
         $response = new Response();
         $response->setContent($content);
         $response->setStatusCode($accessDeniedException->getCode());
         return $response;
     }
 }