コード例 #1
0
 /**
  * Publish an 'onException' event by calling all listeners that have registered to receive it.
  *
  * @param   Exception           $exception  The exception to be published.
  * @param  array|Traversable    $attributes An associative array or a Traversable object
  * @param  mixed                $target     The event target
  * @return  KEventException
  */
 public function publishException(Exception $exception, $attributes = array(), $target = null)
 {
     //Make sure we have an event object
     $event = new KEventException('onException', $attributes, $target);
     $event->setException($exception);
     parent::publishEvent($event);
 }
コード例 #2
0
 public function onException(KEventException $event)
 {
     $exception = $event->getException();
     if ($exception instanceof KHttpExceptionUnauthorized) {
         $request = $this->getObject('request');
         $response = $this->getObject('response');
         if ($request->getFormat() == 'html' && $request->isSafe()) {
             $message = $this->getObject('translator')->translate('You are not authorized to access this resource. Please login and try again.');
             if (JFactory::getApplication()->isSite()) {
                 $url = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode((string) $request->getUrl()), false);
             } else {
                 $url = JRoute::_('index.php', false);
             }
             $response->setRedirect($url, $message, 'error');
             $response->send();
             $event->stopPropagation();
         }
     }
 }
コード例 #3
0
ファイル: http.php プロジェクト: kosmosby/medicine-prof
    /**
     * Redirects guest users to login form on 404 errors if the entity can be accessed without the viewlevel filter
     *
     * @param KEventException $event
     */
    public function onExceptionNotFound(KEventException $event)
    {
        if ($event->getException()->getCode() === KHttpResponse::NOT_FOUND && !$this->getObject('user')->isAuthentic()
            && $event->getException()->getMessage() !== 'File not found')
        {
            $model = $this->getController()->getModel();
            $model->setState(array('access' => null));

            if (!$model->fetch()->isNew())
            {
                $message = $this->getObject('translator')->translate('You are not authorized to access this resource. Please login and try again.');
                $url = JRoute::_('index.php?option=com_users&view=login&return='.base64_encode((string) $this->getRequest()->getUrl()), false);

                $this->getResponse()->setRedirect($url, $message, 'error');
                $this->getResponse()->send();

                $event->stopPropagation();
            }
        }
    }
コード例 #4
0
ファイル: koowa.php プロジェクト: daodaoliang/nooku-framework
 /**
  * Handles 404 errors gracefully after log outs
  *
  * If a user does not have access to the entity after logging out, they will be redirected to the homepage.
  *
  * @param KEventException $event
  * @return bool
  */
 public function onErrorAfterLogout(KEventException $event)
 {
     if ($event->getException()->getCode() === KHttpResponse::NOT_FOUND && JFactory::getApplication()->isSite()) {
         if (version_compare(JVERSION, '3.0', '<')) {
             $hash = JApplication::getHash('plgSystemLogout');
             // Watch out. Starts with lowercase p for 2.5
         } else {
             $hash = JApplicationHelper::getHash('PlgSystemLogout');
         }
         $app = JFactory::getApplication();
         if ($app->input->cookie->getString($hash, null)) {
             $app->enqueueMessage(JText::_('PLG_SYSTEM_LOGOUT_REDIRECT'));
             $app->redirect('index.php');
             return true;
         }
     }
 }