Пример #1
0
 /**
  * Get request deserializer.
  *
  * @return \Magento\Webapi\Controller\Rest\Request\DeserializerInterface
  */
 protected function _getDeserializer()
 {
     if (null === $this->_deserializer) {
         $this->_deserializer = $this->_deserializerFactory->get($this->getContentType());
     }
     return $this->_deserializer;
 }
Пример #2
0
 /**
  * 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);
 }