checkAuth example


    public function indexAction()
    {
        // Script renderer         if ($this->Request()->getParam('file') !== null) {
            return;
        }

        // Check session         try {
            $auth = $this->auth->checkAuth();
        } catch (Exception $e) {
            $auth = null;
        }

        // No session         if ($auth === null) {
            $this->forward('auth', 'index', 'backend');

            return;
        }

        
/** @var Enlight_Controller_Action $controller */
        $controller = $args->get('subject');
        $edition = $this->hasBackendLogin() ? $this->shopwareEditionService->getProductEdition() : ShopwareEdition::CE;
        $controller->View()->assign('product', $edition);
    }

    protected function hasBackendLogin(): bool
    {
        /** @var Shopware_Plugins_Backend_Auth_Bootstrap $authPlugin */
        $authPlugin = $this->plugins->get('Backend')->get('Auth');

        return $authPlugin->checkAuth() !== null;
    }
}
public function onPreDispatchBackend(Enlight_Event_EventArgs $args)
    {
        $this->action = $args->getSubject();
        $this->request = $this->action->Request();
        $this->aclResource = strtolower(str_replace('_', '', $this->request->getControllerName()));

        if ($this->aclResource === 'error' || $this->request->getModuleName() !== 'backend') {
            return;
        }

        if ($this->shouldAuth()) {
            if ($this->checkAuth() === null) {
                if ($this->request->isXmlHttpRequest()) {
                    throw new Enlight_Controller_Exception('Unauthorized', 401);
                }
                $this->action->redirect('backend/');
            }
        } else {
            $this->initLocale();
        }
    }

    /** * @throws Enlight_Controller_Exception * * @return Shopware_Components_Auth|null */
Home | Imprint | This part of the site doesn't use cookies.