ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModule1\Controller;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
|
||||
use Magento\Framework\Stdlib\Cookie\PhpCookieManager;
|
||||
|
||||
/**
|
||||
* Controller for testing the CookieManager.
|
||||
*
|
||||
*/
|
||||
abstract class CookieTester implements \Magento\Framework\App\ActionInterface
|
||||
{
|
||||
/** @var PhpCookieManager */
|
||||
protected $cookieManager;
|
||||
|
||||
/** @var CookieMetadataFactory */
|
||||
protected $cookieMetadataFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResponseInterface
|
||||
*/
|
||||
protected $_response;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\App\Action\Context $context
|
||||
* @param PhpCookieManager $cookieManager
|
||||
* @param CookieMetadataFactory $cookieMetadataFactory
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Action\Context $context,
|
||||
PhpCookieManager $cookieManager,
|
||||
CookieMetadataFactory $cookieMetadataFactory
|
||||
) {
|
||||
$this->cookieManager = $cookieManager;
|
||||
$this->cookieMetadataFactory = $cookieMetadataFactory;
|
||||
$this->_response = $context->getResponse();
|
||||
$this->request = $context->getRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve cookie metadata factory
|
||||
*/
|
||||
protected function getCookieMetadataFactory()
|
||||
{
|
||||
return $this->cookieMetadataFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve cookie metadata factory
|
||||
*/
|
||||
protected function getCookieManager()
|
||||
{
|
||||
return $this->cookieManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch request
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
* @return \Magento\Framework\App\ResponseInterface
|
||||
*/
|
||||
public function dispatch(RequestInterface $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$result = $this->execute();
|
||||
return $result ? $result : $this->_response;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModule1\Controller\CookieTester;
|
||||
|
||||
use \Magento\Framework\App\RequestInterface;
|
||||
|
||||
/**
|
||||
* Controller to test deletion of a cookie
|
||||
*/
|
||||
class DeleteCookie extends \Magento\TestModule1\Controller\CookieTester
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @return \Magento\Framework\App\ResponseInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$cookieName = $this->request->getParam('cookie_name');
|
||||
$this->getCookieManager()->deleteCookie($cookieName);
|
||||
return $this->_response;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModule1\Controller\CookieTester;
|
||||
|
||||
use \Magento\Framework\App\RequestInterface;
|
||||
|
||||
/**
|
||||
*/
|
||||
class SetPublicCookie extends \Magento\TestModule1\Controller\CookieTester
|
||||
{
|
||||
/**
|
||||
* Sets a public cookie with data from url parameters
|
||||
*
|
||||
* @return \Magento\Framework\App\ResponseInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$publicCookieMetadata = $this->getCookieMetadataFactory()->createPublicCookieMetadata();
|
||||
|
||||
$cookieDomain = $this->request->getParam('cookie_domain');
|
||||
if ($cookieDomain !== null) {
|
||||
$publicCookieMetadata->setDomain($cookieDomain);
|
||||
}
|
||||
|
||||
$cookiePath = $this->request->getParam('cookie_path');
|
||||
if ($cookiePath !== null) {
|
||||
$publicCookieMetadata->setPath($cookiePath);
|
||||
}
|
||||
|
||||
$cookieDuration = $this->request->getParam('cookie_duration');
|
||||
if ($cookieDuration !== null) {
|
||||
$publicCookieMetadata->setDuration($cookieDuration);
|
||||
}
|
||||
|
||||
$httpOnly = $this->request->getParam('cookie_httponly');
|
||||
if ($httpOnly !== null) {
|
||||
$publicCookieMetadata->setHttpOnly($httpOnly);
|
||||
}
|
||||
|
||||
$secure = $this->request->getParam('cookie_secure');
|
||||
if ($secure !== null) {
|
||||
$publicCookieMetadata->setSecure($secure);
|
||||
}
|
||||
|
||||
$cookieName = $this->request->getParam('cookie_name');
|
||||
$cookieValue = $this->request->getParam('cookie_value');
|
||||
$this->getCookieManager()->setPublicCookie($cookieName, $cookieValue, $publicCookieMetadata);
|
||||
return $this->_response;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\TestModule1\Controller\CookieTester;
|
||||
|
||||
use \Magento\Framework\App\RequestInterface;
|
||||
|
||||
/**
|
||||
*/
|
||||
class SetSensitiveCookie extends \Magento\TestModule1\Controller\CookieTester
|
||||
{
|
||||
/**
|
||||
* Sets a sensitive cookie with data from url parameters
|
||||
*
|
||||
* @return \Magento\Framework\App\ResponseInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$sensitiveCookieMetadata = $this->getCookieMetadataFactory()->createSensitiveCookieMetadata();
|
||||
|
||||
$cookieDomain = $this->request->getParam('cookie_domain');
|
||||
if ($cookieDomain !== null) {
|
||||
$sensitiveCookieMetadata->setDomain($cookieDomain);
|
||||
}
|
||||
$cookiePath = $this->request->getParam('cookie_domain');
|
||||
if ($cookiePath !== null) {
|
||||
$sensitiveCookieMetadata->setPath($cookiePath);
|
||||
}
|
||||
|
||||
$cookieName = $this->request->getParam('cookie_name');
|
||||
$cookieValue = $this->request->getParam('cookie_value');
|
||||
$this->getCookieManager()->setSensitiveCookie($cookieName, $cookieValue, $sensitiveCookieMetadata);
|
||||
return $this->_response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user