コード例 #1
0
 /**
  * Check authenticate.
  *
  * @param ExecuteActionEvent $event
  * @param Config $config
  * @throws ValueNotFoundException
  * @throws PermissionDeniedException
  */
 private function execute(ExecuteActionEvent $event, $config)
 {
     $request = $event->getRequest();
     $session = $request->getSession();
     try {
         $session->get('authenticate.user_id');
         if ($this->maxTime > 0) {
             if ($session->get('authenticate.epoch') < time()) {
                 //deprecated session
                 $session->clear();
                 throw new ValueNotFoundException('authenticate.epoch');
             }
             $session->set('authenticate.epoch', time() + $this->maxTime);
         }
         if ($config->getAttribute('auth-redirect') !== false) {
             $response = $this->createResponseRedirect($config->getAttribute('auth-redirect'), $request);
             $event->setResponse($response);
         }
     } catch (ValueNotFoundException $e) {
         if ($config->getAttribute('unauth-redirect') !== false) {
             $response = $this->createResponseRedirect($config->getAttribute('unauth-redirect'), $request);
             $event->setResponse($response);
         } else {
             if ($config->getAttribute('auth-redirect') !== false) {
                 //ignore
             } else {
                 throw new PermissionDeniedException();
             }
         }
     }
 }
コード例 #2
0
ファイル: ArgumentEvent.php プロジェクト: itephp/framework
 /**
  * Detect config argument.
  *
  * @param ExecuteActionEvent $event
  */
 public function onExecuteAction(ExecuteActionEvent $event)
 {
     $request = $event->getRequest();
     $position = 1;
     foreach ($request->getConfig()->getNodes('argument') as $argument) {
         $this->validateArgument($request, $argument, $position++);
     }
 }