本文整理汇总了PHP中Magento\Framework\Session\Generic::setUserType方法的典型用法代码示例。如果您正苦于以下问题:PHP Generic::setUserType方法的具体用法?PHP Generic::setUserType怎么用?PHP Generic::setUserType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Session\Generic
的用法示例。
在下文中一共展示了Generic::setUserType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Initiate a session for unregistered users. Send back the session id.
*
* @return void
*/
public function execute()
{
$this->session->start('frontend');
$this->session->setUserId(0);
$this->session->setUserType(UserIdentifier::USER_TYPE_GUEST);
$this->session->regenerateId(true);
}
示例2: execute
/**
* Login registered users and initiate a session. Send back the session id.
*
* Expects a POST. ex for JSON {"username":"user@magento.com", "password":"userpassword"}
*
* @return void
*/
public function execute()
{
$contentTypeHeaderValue = $this->getRequest()->getHeader('Content-Type');
$contentType = $this->getContentType($contentTypeHeaderValue);
$loginData = null;
try {
$loginData = $this->deserializerFactory->get($contentType)->deserialize($this->getRequest()->getRawBody());
} catch (Exception $e) {
$this->getResponse()->setHttpResponseCode($e->getCode());
return;
}
if (!$loginData || $this->getRequest()->getMethod() !== \Magento\Webapi\Model\Rest\Config::HTTP_METHOD_POST) {
$this->getResponse()->setHttpResponseCode(HttpException::HTTP_BAD_REQUEST);
return;
}
$customerData = null;
try {
$customerData = $this->customerAccountService->authenticate($loginData['username'], $loginData['password']);
} catch (AuthenticationException $e) {
$this->getResponse()->setHttpResponseCode(HttpException::HTTP_UNAUTHORIZED);
return;
}
$this->session->start('frontend');
$this->session->setUserId($customerData->getId());
$this->session->setUserType(UserIdentifier::USER_TYPE_CUSTOMER);
$this->session->regenerateId(true);
}