Example #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;
 }
Example #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);
 }
Example #3
0
 /**
  * Prepare SUT for GetBodyParams() method mock.
  *
  * @param array $params
  */
 protected function _prepareSutForGetBodyParamsTest($params)
 {
     $rawBody = 'rawBody';
     $this->_request->expects($this->once())->method('getRawBody')->will($this->returnValue($rawBody));
     $contentType = 'contentType';
     $this->_request->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue($contentType));
     $deserializer = $this->getMockBuilder('Magento\\Webapi\\Controller\\Rest\\Request\\Deserializer\\Json')->disableOriginalConstructor()->setMethods(array('deserialize'))->getMock();
     $deserializer->expects($this->once())->method('deserialize')->with($rawBody)->will($this->returnValue($params));
     $this->_deserializerFactory->expects($this->once())->method('get')->with($contentType)->will($this->returnValue($deserializer));
 }