コード例 #1
0
ファイル: Anonymous.php プロジェクト: Atlis/docker-magento2
 /**
  * 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
0
ファイル: Index.php プロジェクト: Atlis/docker-magento2
 /**
  * Login registered users and initiate a session. Send back the session id.
  *
  * Expects a POST. ex for JSON  {"username":"******", "password":"******"}
  *
  * @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);
 }