Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
merge magento/2.3-develop into magento-epam/EPAM-PR-81
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-mts-svc authored Oct 15, 2019
2 parents d542477 + 128c2ad commit 17f05b3
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 4 deletions.
45 changes: 45 additions & 0 deletions app/code/Magento/Cookie/Block/DataProviders/SessionConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Cookie\Block\DataProviders;

use Magento\Framework\Session\Config\ConfigInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* Provide cookie configuration
*/
class SessionConfig implements ArgumentInterface
{
/**
* Session config
*
* @var ConfigInterface
*/
private $sessionConfig;

/**
* Constructor
*
* @param ConfigInterface $sessionConfig
*/
public function __construct(
ConfigInterface $sessionConfig
) {
$this->sessionConfig = $sessionConfig;
}
/**
* Get session.cookie_secure
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
public function getCookieSecure()
{
return $this->sessionConfig->getCookieSecure();
}
}
18 changes: 18 additions & 0 deletions app/code/Magento/Cookie/view/adminhtml/layout/default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="after.body.start">
<block class="Magento\Framework\View\Element\Js\Cookie" name="cookie_config" template="Magento_Cookie::html/cookie.phtml">
<arguments>
<argument name="session_config" xsi:type="object">Magento\Cookie\Block\DataProviders\SessionConfig</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
10 changes: 10 additions & 0 deletions app/code/Magento/Cookie/view/base/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

var config = {
paths: {
'jquery/jquery-storageapi': 'Magento_Cookie/js/jquery.storageapi.extended'
}
};
17 changes: 17 additions & 0 deletions app/code/Magento/Cookie/view/base/templates/html/cookie.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/**
* Cookie settings initialization script
*
* @var $block \Magento\Framework\View\Element\Js\Cookie
*/
?>

<script>
window.cookiesConfig = window.cookiesConfig || {};
window.cookiesConfig.secure = <?= /* @noEscape */ $block->getSessionConfig()->getCookieSecure() ? 'true' : 'false' ?>;
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'jquery',
'jquery/jquery.cookie',
'jquery/jquery.storageapi.min'
], function ($) {
'use strict';

/**
*
* @param {Object} storage
* @private
*/
function _extend(storage) {
$.extend(storage, {
_secure: window.cookiesConfig ? window.cookiesConfig.secure : false,

/**
* Set value under name
* @param {String} name
* @param {String} value
* @param {Object} [options]
*/
setItem: function (name, value, options) {
var _default = {
expires: this._expires,
path: this._path,
domain: this._domain,
secure: this._secure
};

$.cookie(this._prefix + name, value, $.extend(_default, options || {}));
},

/**
* Set default options
* @param {Object} c
* @returns {storage}
*/
setConf: function (c) {
if (c.path) {
this._path = c.path;
}

if (c.domain) {
this._domain = c.domain;
}

if (c.expires) {
this._expires = c.expires;
}

if (typeof c.secure !== 'undefined') {
this._secure = c.secure;
}

return this;
}
});
}

if (window.cookieStorage) {
_extend(window.cookieStorage);
}
});
5 changes: 5 additions & 0 deletions app/code/Magento/Cookie/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<body>
<referenceContainer name="after.body.start">
<block class="Magento\Cookie\Block\Html\Notices" name="cookie_notices" template="Magento_Cookie::html/notices.phtml"/>
<block class="Magento\Framework\View\Element\Js\Cookie" name="cookie_config" template="Magento_Cookie::html/cookie.phtml">
<arguments>
<argument name="session_config" xsi:type="object">Magento\Cookie\Block\DataProviders\SessionConfig</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
10 changes: 6 additions & 4 deletions app/code/Magento/PageCache/Plugin/RegisterFormKeyFromCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
namespace Magento\PageCache\Plugin;

use Magento\Framework\App\PageCache\FormKey as CacheFormKey;
use Magento\Framework\Escaper;
use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
use Magento\Framework\Escaper;
use Magento\Framework\Session\Config\ConfigInterface;
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;

/**
* Allow for registration of a form key through cookies.
Expand Down Expand Up @@ -46,7 +46,7 @@ class RegisterFormKeyFromCookie
private $sessionConfig;

/**
* @param CacheFormKey $formKey
* @param CacheFormKey $cacheFormKey
* @param Escaper $escaper
* @param FormKey $formKey
* @param CookieMetadataFactory $cookieMetadataFactory
Expand All @@ -70,7 +70,6 @@ public function __construct(
* Set form key from the cookie.
*
* @return void
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeDispatch(): void
Expand All @@ -85,6 +84,8 @@ public function beforeDispatch(): void
}

/**
* Set form key cookie
*
* @param string $formKey
* @return void
*/
Expand All @@ -94,6 +95,7 @@ private function updateCookieFormKey(string $formKey): void
->createPublicCookieMetadata();
$cookieMetadata->setDomain($this->sessionConfig->getCookieDomain());
$cookieMetadata->setPath($this->sessionConfig->getCookiePath());
$cookieMetadata->setSecure($this->sessionConfig->getCookieSecure());
$lifetime = $this->sessionConfig->getCookieLifetime();
if ($lifetime !== 0) {
$cookieMetadata->setDuration($lifetime);
Expand Down

0 comments on commit 17f05b3

Please sign in to comment.