Cake\Controller\Component\AuthComponent::authCheck PHP Метод

authCheck() публичный Метод

The auth check is done when event name is same as the one configured in checkAuthIn config.
public authCheck ( Cake\Event\Event $event ) : Response | null
$event Cake\Event\Event Event instance.
Результат Cake\Network\Response | null
    public function authCheck(Event $event)
    {
        if ($this->_config['checkAuthIn'] !== $event->name()) {
            return null;
        }
        /* @var \Cake\Controller\Controller $controller */
        $controller = $event->subject();
        $action = strtolower($controller->request->params['action']);
        if (!$controller->isAction($action)) {
            return null;
        }
        $this->_setDefaults();
        if ($this->_isAllowed($controller)) {
            return null;
        }
        $isLoginAction = $this->_isLoginAction($controller);
        if (!$this->_getUser()) {
            if ($isLoginAction) {
                return null;
            }
            $result = $this->_unauthenticated($controller);
            if ($result instanceof Response) {
                $event->stopPropagation();
            }
            return $result;
        }
        if ($isLoginAction || empty($this->_config['authorize']) || $this->isAuthorized($this->user())) {
            return null;
        }
        $event->stopPropagation();
        return $this->_unauthorized($controller);
    }

Usage Example

Пример #1
0
 public function authCheck(Event $event)
 {
     if (isset($this->earlyAuthTest)) {
         if ($this->_config['checkAuthIn'] !== $event->name()) {
             return;
         }
         $this->authCheckCalledFrom = $event->name();
         return;
     }
     return parent::authCheck($event);
 }