Skip to content

Commit

Permalink
Merge pull request #9309 from adobe-commerce-tier-4/PR_13_OCT_2024
Browse files Browse the repository at this point in the history
[Support Tier-4 odubovyk] 10-13-2024 Regular delivery of bugfixes and improvements
  • Loading branch information
2 parents 9c48c55 + f4a9461 commit ec7e32a
Show file tree
Hide file tree
Showing 32 changed files with 916 additions and 155 deletions.
36 changes: 12 additions & 24 deletions app/code/Magento/Customer/Model/Authentication.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2016 Adobe
* All Rights Reserved.
*/
namespace Magento\Customer\Model;

use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\ResourceModel\CustomerRepository;
use Magento\Customer\Model\CustomerAuthUpdate;
use Magento\Backend\App\ConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Encryption\EncryptorInterface as Encryptor;
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
use Magento\Framework\Exception\State\UserLockedException;

/**
* Class Authentication
* Class Authentication model
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Authentication implements AuthenticationInterface
{
/**
* Configuration path to customer lockout threshold
*/
const LOCKOUT_THRESHOLD_PATH = 'customer/password/lockout_threshold';
public const LOCKOUT_THRESHOLD_PATH = 'customer/password/lockout_threshold';

/**
* Configuration path to customer max login failures number
*/
const MAX_FAILURES_PATH = 'customer/password/lockout_failures';
public const MAX_FAILURES_PATH = 'customer/password/lockout_failures';

/**
* @var CustomerRegistry
Expand Down Expand Up @@ -67,19 +67,22 @@ class Authentication implements AuthenticationInterface
* @param ConfigInterface $backendConfig
* @param \Magento\Framework\Stdlib\DateTime $dateTime
* @param Encryptor $encryptor
* @param CustomerAuthUpdate|null $customerAuthUpdate
*/
public function __construct(
CustomerRepositoryInterface $customerRepository,
CustomerRegistry $customerRegistry,
ConfigInterface $backendConfig,
\Magento\Framework\Stdlib\DateTime $dateTime,
Encryptor $encryptor
Encryptor $encryptor,
CustomerAuthUpdate $customerAuthUpdate = null
) {
$this->customerRepository = $customerRepository;
$this->customerRegistry = $customerRegistry;
$this->backendConfig = $backendConfig;
$this->dateTime = $dateTime;
$this->encryptor = $encryptor;
$this->customerAuthUpdate = $customerAuthUpdate ?: ObjectManager::getInstance()->get(CustomerAuthUpdate::class);
}

/**
Expand Down Expand Up @@ -116,7 +119,7 @@ public function processAuthenticationFailure($customerId)
}

$customerSecure->setFailuresNum($failuresNum);
$this->getCustomerAuthUpdate()->saveAuth($customerId);
$this->customerAuthUpdate->saveAuth($customerId);
}

/**
Expand All @@ -128,7 +131,7 @@ public function unlock($customerId)
$customerSecure->setFailuresNum(0);
$customerSecure->setFirstFailure(null);
$customerSecure->setLockExpires(null);
$this->getCustomerAuthUpdate()->saveAuth($customerId);
$this->customerAuthUpdate->saveAuth($customerId);
}

/**
Expand Down Expand Up @@ -176,19 +179,4 @@ public function authenticate($customerId, $password)
}
return true;
}

/**
* Get customer authentication update model
*
* @return \Magento\Customer\Model\CustomerAuthUpdate
* @deprecated 100.1.1
*/
private function getCustomerAuthUpdate()
{
if ($this->customerAuthUpdate === null) {
$this->customerAuthUpdate =
\Magento\Framework\App\ObjectManager::getInstance()->get(CustomerAuthUpdate::class);
}
return $this->customerAuthUpdate;
}
}
7 changes: 5 additions & 2 deletions app/code/Magento/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/

namespace Magento\Customer\Model;
Expand Down Expand Up @@ -1415,5 +1415,8 @@ public function getPassword()
public function _resetState(): void
{
$this->_errors = [];
$this->_origData = null;
$this->storedData = [];
$this->_data = [];
}
}
23 changes: 11 additions & 12 deletions app/code/Magento/Customer/Model/CustomerAuthUpdate.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2016 Adobe
* All Rights Reserved.
*/

namespace Magento\Customer\Model;

use Magento\Customer\Model\ResourceModel\Customer as CustomerResourceModel;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\NoSuchEntityException;

/**
Expand All @@ -26,23 +25,23 @@ class CustomerAuthUpdate
protected $customerResourceModel;

/**
* @var Customer
* @var CustomerFactory
*/
private $customerModel;
private $customerFactory;

/**
* @param CustomerRegistry $customerRegistry
* @param CustomerResourceModel $customerResourceModel
* @param Customer|null $customerModel
* @param CustomerFactory $customerFactory
*/
public function __construct(
CustomerRegistry $customerRegistry,
CustomerResourceModel $customerResourceModel,
Customer $customerModel = null
CustomerFactory $customerFactory
) {
$this->customerRegistry = $customerRegistry;
$this->customerResourceModel = $customerResourceModel;
$this->customerModel = $customerModel ?: ObjectManager::getInstance()->get(Customer::class);
$this->customerFactory = $customerFactory;
}

/**
Expand All @@ -55,9 +54,9 @@ public function __construct(
public function saveAuth($customerId)
{
$customerSecure = $this->customerRegistry->retrieveSecureData($customerId);

$this->customerResourceModel->load($this->customerModel, $customerId);
$currentLockExpiresVal = $this->customerModel->getData('lock_expires');
$customerModel = $this->customerFactory->create();
$this->customerResourceModel->load($customerModel, $customerId);
$currentLockExpiresVal = $customerModel->getData('lock_expires');
$newLockExpiresVal = $customerSecure->getData('lock_expires');

$this->customerResourceModel->getConnection()->update(
Expand All @@ -71,7 +70,7 @@ public function saveAuth($customerId)
);

if ($currentLockExpiresVal !== $newLockExpiresVal) {
$this->customerModel->reindex();
$customerModel->reindex();
}

return $this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2016 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

namespace Magento\Customer\Test\Unit\Model;

use Magento\Customer\Model\Customer as CustomerModel;
use Magento\Customer\Model\CustomerFactory;
use Magento\Customer\Model\CustomerAuthUpdate;
use Magento\Customer\Model\CustomerRegistry;
use Magento\Customer\Model\Data\CustomerSecure;
Expand Down Expand Up @@ -36,9 +37,9 @@ class CustomerAuthUpdateTest extends TestCase
protected $customerResourceModel;

/**
* @var CustomerModel|MockObject
* @var CustomerFactory|MockObject
*/
protected $customerModel;
protected $customerFactory;

/**
* @var ObjectManager
Expand All @@ -56,15 +57,15 @@ protected function setUp(): void
$this->createMock(CustomerRegistry::class);
$this->customerResourceModel =
$this->createMock(CustomerResourceModel::class);
$this->customerModel =
$this->createMock(CustomerModel::class);
$this->customerFactory =
$this->createMock(CustomerFactory::class);

$this->model = $this->objectManager->getObject(
CustomerAuthUpdate::class,
[
'customerRegistry' => $this->customerRegistry,
'customerResourceModel' => $this->customerResourceModel,
'customerModel' => $this->customerModel
'customerFactory' => $this->customerFactory
]
);
}
Expand Down Expand Up @@ -115,9 +116,14 @@ public function testSaveAuth()
$customerId
);

$this->customerModel->expects($this->once())
$customerModel = $this->createMock(CustomerModel::class);
$customerModel->expects($this->once())
->method('reindex');

$this->customerFactory->expects($this->once())
->method('create')
->willReturn($customerModel);

$this->model->saveAuth($customerId);
}
}
7 changes: 5 additions & 2 deletions app/code/Magento/CustomerGraphQl/etc/graphql/events.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2021 Adobe
* All Rights Reserved.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="customer_login">
<observer name="customer_log_login" instance="Magento\Customer\Observer\LogLastLoginAtObserver" />
</event>
<event name="customer_customer_authenticated">
<observer name="customer_unlock" instance="Magento\Customer\Observer\CustomerLoginSuccessObserver" />
</event>
</config>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2012 Adobe
* All Rights Reserved.
*/

namespace Magento\CustomerImportExport\Model\Import;

use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryWithWebsites as CountryWithWebsitesSource;
use Magento\CustomerImportExport\Model\Import\CountryWithWebsites as CountryWithWebsitesSource;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\App\ObjectManager;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
Expand Down Expand Up @@ -365,7 +365,7 @@ public function getAttributeOptions(AbstractAttribute $attribute, array $indexAt
if ($attribute->getAttributeCode() === 'country_id') {
//If we want to get available options for country field then we have to use alternative source
// to get actual data for each website.
$options = $this->countryWithWebsites->getAllOptions();
$options = $this->countryWithWebsites->getCountiesPerWebsite();
//Available country options now will be sorted by websites.
$code = $attribute->getAttributeCode();
$websiteOptions = [Store::DEFAULT_STORE_ID => $standardOptions];
Expand Down
Loading

0 comments on commit ec7e32a

Please sign in to comment.