本文整理汇总了PHP中Magento\Framework\Session\Generic::getUserId方法的典型用法代码示例。如果您正苦于以下问题:PHP Generic::getUserId方法的具体用法?PHP Generic::getUserId怎么用?PHP Generic::getUserId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Session\Generic
的用法示例。
在下文中一共展示了Generic::getUserId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _checkPermissions
/**
* Perform authentication and authorization.
*
* Authentication can be based on active customer/guest session or it can be based on OAuth headers.
*
* @throws \Magento\Framework\Exception\AuthorizationException
* @return void
*/
protected function _checkPermissions()
{
/**
* All mobile clients are expected to pass session cookie along with the request which will allow
* to start session automatically. User ID and user type are initialized when session is created
* during login call.
*/
$userId = $this->session->getUserId();
$userType = $this->session->getUserType();
$userIdentifier = null;
$consumerId = null;
if ($userType) {
/** @var \Magento\Authz\Model\UserIdentifier $userIdentifier */
$userIdentifier = $this->_objectManager->create('Magento\\Authz\\Model\\UserIdentifier', ['userType' => $userType, 'userId' => $userId]);
} else {
$oauthRequest = $this->_oauthHelper->prepareRequest($this->_request);
$consumerId = $this->_oauthService->validateAccessTokenRequest($oauthRequest, $this->_oauthHelper->getRequestUrl($this->_request), $this->_request->getMethod());
$this->_request->setConsumerId($consumerId);
}
$route = $this->_getCurrentRoute();
if (!$this->_authorizationService->isAllowed($route->getAclResources(), $userIdentifier)) {
$params = ['resources' => implode(', ', $route->getAclResources())];
throw new AuthorizationException(AuthorizationException::NOT_AUTHORIZED, $params);
}
}