Skip to content

Commit b40bd3c

Browse files
committed
ACP2E-1972: reset visitor data before login, in case a previous post request generated a new visitor session
1 parent f631b97 commit b40bd3c

File tree

4 files changed

+12
-81
lines changed

4 files changed

+12
-81
lines changed

app/code/Magento/Customer/Controller/Account/LoginPost.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313
use Magento\Customer\Api\AccountManagementInterface;
1414
use Magento\Customer\Model\Url as CustomerUrl;
1515
use Magento\Framework\App\CsrfAwareActionInterface;
16+
use Magento\Framework\App\ObjectManager;
1617
use Magento\Framework\App\Request\InvalidRequestException;
1718
use Magento\Framework\App\RequestInterface;
1819
use Magento\Framework\Controller\Result\Redirect;
1920
use Magento\Framework\Exception\EmailNotConfirmedException;
2021
use Magento\Framework\Exception\AuthenticationException;
2122
use Magento\Framework\Data\Form\FormKey\Validator;
2223
use Magento\Framework\Exception\LocalizedException;
23-
use Magento\Framework\Exception\State\UserLockedException;
2424
use Magento\Framework\App\Config\ScopeConfigInterface;
2525
use Magento\Customer\Controller\AbstractAccount;
2626
use Magento\Framework\Phrase;
27+
use Magento\Framework\Session\Generic;
2728

2829
/**
2930
* Post login customer action.
@@ -72,27 +73,35 @@ class LoginPost extends AbstractAccount implements CsrfAwareActionInterface, Htt
7273
*/
7374
private $customerUrl;
7475

76+
/**
77+
* @var Generic
78+
*/
79+
private $generic;
80+
7581
/**
7682
* @param Context $context
7783
* @param Session $customerSession
7884
* @param AccountManagementInterface $customerAccountManagement
7985
* @param CustomerUrl $customerHelperData
8086
* @param Validator $formKeyValidator
8187
* @param AccountRedirect $accountRedirect
88+
* @param Generic $generic
8289
*/
8390
public function __construct(
8491
Context $context,
8592
Session $customerSession,
8693
AccountManagementInterface $customerAccountManagement,
8794
CustomerUrl $customerHelperData,
8895
Validator $formKeyValidator,
89-
AccountRedirect $accountRedirect
96+
AccountRedirect $accountRedirect,
97+
Generic $generic = null
9098
) {
9199
$this->session = $customerSession;
92100
$this->customerAccountManagement = $customerAccountManagement;
93101
$this->customerUrl = $customerHelperData;
94102
$this->formKeyValidator = $formKeyValidator;
95103
$this->accountRedirect = $accountRedirect;
104+
$this->generic = $generic ?? ObjectManager::getInstance()->get(Generic::class);
96105
parent::__construct($context);
97106
}
98107

@@ -188,6 +197,7 @@ public function execute()
188197
$login = $this->getRequest()->getPost('login');
189198
if (!empty($login['username']) && !empty($login['password'])) {
190199
try {
200+
$this->generic->setVisitorData([]);
191201
$customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
192202
$this->session->setCustomerDataAsLoggedIn($customer);
193203
if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {

app/code/Magento/Customer/Model/ResourceModel/Visitor.php

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -122,62 +122,6 @@ public function fetchCreatedAt(int $visitorId): ?int
122122
return strtotime($lookup['created_at']);
123123
}
124124

125-
/**
126-
* Gets created at value for the visitor id by customer id
127-
*
128-
* @param int $customerId
129-
* @return int|null
130-
*/
131-
public function fetchCreatedAtByCustomer(int $customerId): ?int
132-
{
133-
$connection = $this->getConnection();
134-
$select = $connection->select()->from(
135-
['visitor_table' => $this->getTable('customer_visitor')],
136-
['created_at' => 'visitor_table.created_at']
137-
)->where(
138-
'visitor_table.customer_id = ?',
139-
$customerId,
140-
\Zend_Db::INT_TYPE
141-
)->order(
142-
'visitor_table.visitor_id DESC'
143-
)->limit(
144-
1
145-
);
146-
$lookup = $connection->fetchRow($select);
147-
if (empty($lookup) || $lookup['created_at'] == null) {
148-
return null;
149-
}
150-
return strtotime($lookup['created_at']);
151-
}
152-
153-
/**
154-
* Gets created at value for the visitor id by customer id
155-
*
156-
* @param int $customerId
157-
* @return int|null
158-
*/
159-
public function fetchLastVisitAtByCustomer(int $customerId): ?int
160-
{
161-
$connection = $this->getConnection();
162-
$select = $connection->select()->from(
163-
['visitor_table' => $this->getTable('customer_visitor')],
164-
['last_visit_at' => 'visitor_table.last_visit_at']
165-
)->where(
166-
'visitor_table.customer_id = ?',
167-
$customerId,
168-
\Zend_Db::INT_TYPE
169-
)->order(
170-
'visitor_table.visitor_id DESC'
171-
)->limit(
172-
1
173-
);
174-
$lookup = $connection->fetchRow($select);
175-
if (empty($lookup) || $lookup['last_visit_at'] == null) {
176-
return null;
177-
}
178-
return strtotime($lookup['last_visit_at']);
179-
}
180-
181125
/**
182126
* Update visitor session created at column value
183127
*
@@ -193,20 +137,4 @@ public function updateCreatedAt(int $visitorId, int $timestamp): void
193137
$this->getConnection()->quoteInto('visitor_id = ?', $visitorId)
194138
);
195139
}
196-
197-
/**
198-
* Update visitor session visitor id column value
199-
*
200-
* @param int $visitorId
201-
* @param int $customerId
202-
* @return void
203-
*/
204-
public function updateCustomerId(int $visitorId, int $customerId): void
205-
{
206-
$this->getConnection()->update(
207-
$this->getTable('customer_visitor'),
208-
['customer_id' => $customerId],
209-
$this->getConnection()->quoteInto('visitor_id = ?', $visitorId)
210-
);
211-
}
212140
}

app/code/Magento/Customer/Model/Session/SessionCleaner.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ public function clearFor(int $customerId): void
9898
$timestamp = $dateTime->getTimestamp();
9999
$this->customerResourceModel->updateSessionCutOff($customerId, $timestamp);
100100
if ($this->sessionManager->getVisitorData() !== null) {
101-
102101
$visitorId = $this->sessionManager->getVisitorData()['visitor_id'];
103-
$this->visitorResourceModel->updateCustomerId((int) $visitorId, $customerId);
104102
$this->visitorResourceModel->updateCreatedAt((int) $visitorId, $timestamp + 1);
105103
}
106104
}

app/code/Magento/Customer/Model/Session/Validators/CutoffValidator.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ public function validate(SessionManagerInterface $session): void
6868
) {
6969
$cutoff = $this->customerResource->findSessionCutOff((int) $visitor['customer_id']);
7070
$sessionCreationTime = $this->visitorResource->fetchCreatedAt((int) $visitor['visitor_id']);
71-
$secondSessionCreationTime = $this->visitorResource->fetchCreatedAtByCustomer((int) $visitor['customer_id']);
72-
73-
if ($secondSessionCreationTime > $sessionCreationTime) {
74-
$sessionCreationTime = $secondSessionCreationTime;
75-
}
7671
if (isset($cutoff, $sessionCreationTime) && $cutoff > $sessionCreationTime) {
7772
throw new SessionException(
7873
new Phrase('The session has expired, please login again.')

0 commit comments

Comments
 (0)