Skip to content

Commit 3931e78

Browse files
committed
ACP2E-3501: VAPT: Business Logic Error - future date as customer date of birth
1 parent 9720daf commit 3931e78

File tree

1 file changed

+11
-36
lines changed
  • app/code/Magento/Customer/Model/Validator

1 file changed

+11
-36
lines changed

app/code/Magento/Customer/Model/Validator/Dob.php

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,52 @@
77

88
namespace Magento\Customer\Model\Validator;
99

10+
use DateTimeZone;
1011
use Magento\Customer\Model\Customer;
1112
use Magento\Framework\Validator\AbstractValidator;
12-
use Magento\Store\Api\Data\StoreInterface as StoreInterface;
13-
use Magento\Store\Model\StoreManagerInterface;
1413

1514
/**
1615
* Customer dob field validator.
1716
*/
1817
class Dob extends AbstractValidator
1918
{
2019
/**
21-
* @var \DateTime
22-
*/
23-
private \DateTime $currentDate;
24-
25-
/**
26-
* @var StoreManagerInterface
27-
*/
28-
private StoreManagerInterface $storeManager;
29-
30-
/**
31-
* @param StoreManagerInterface $storeManager
32-
*/
33-
public function __construct(StoreManagerInterface $storeManager)
34-
{
35-
$this->currentDate = new \DateTime();
36-
$this->storeManager = $storeManager;
37-
}
38-
39-
/**
40-
* Validate name fields.
20+
* Validate dob field.
4121
*
4222
* @param Customer $customer
4323
* @return bool
4424
*/
4525
public function isValid($customer): bool
4626
{
47-
if (!$this->isValidDob($customer->getDob(), $customer->getStoreId())) {
48-
parent::_addMessages([['dob' => 'The Date of Birth should not be greater than today.']]);
27+
$timezone = new DateTimeZone($customer->getStore()->getConfig('general/locale/timezone'));
28+
if (!$this->isValidDob($customer->getDob(), $timezone)) {
29+
$this->_addMessages([['dob' => 'The Date of Birth should not be greater than today.']]);
4930
}
5031

51-
return count($this->_messages) == 0;
32+
return count($this->_messages) === 0;
5233
}
5334

5435
/**
5536
* Check if specified dob is not in the future
5637
*
5738
* @param string|null $dobValue
58-
* @param null|string|bool|int|StoreInterface $storeId
39+
* @param DateTimeZone $timezone
5940
* @return bool
6041
*/
61-
private function isValidDob(?string $dobValue, null|string|bool|int|StoreInterface $storeId): bool
42+
private function isValidDob(?string $dobValue, ?DateTimeZone $timezone = null): bool
6243
{
6344
if ($dobValue != null) {
6445

65-
// Get the timezone of the store
66-
$store = $this->storeManager->getStore($storeId);
67-
$timezone = $store->getConfig('general/locale/timezone');
68-
6946
// Get the date of birth and set the time to 00:00:00
70-
$dobDate = new \DateTime($dobValue, new \DateTimeZone($timezone));
47+
$dobDate = new \DateTime($dobValue, $timezone);
7148
$dobDate->setTime(0, 0, 0);
7249

7350
// Get the timestamp of the date of birth and the current date
7451
$dobTimestamp = $dobDate->getTimestamp();
75-
$currentTimestamp = $this->currentDate->getTimestamp();
52+
$currentTimestamp = time();
7653

7754
// If the date's of birth first minute is in the future, return false - the day has not started yet
78-
if ($dobTimestamp > $currentTimestamp) {
79-
return false;
80-
}
55+
return ($dobTimestamp <= $currentTimestamp);
8156
}
8257

8358
return true;

0 commit comments

Comments
 (0)