Skip to content

Commit 55ba690

Browse files
author
mastiuhin-olexandr
committed
MC-35812: Overriding CreatePost can automatically confirm a customer
1 parent 5977749 commit 55ba690

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,6 @@ protected function sendEmailConfirmation(CustomerInterface $customer, $redirectU
977977
$templateType = self::NEW_ACCOUNT_EMAIL_REGISTERED_NO_PASSWORD;
978978
}
979979
$this->getEmailNotification()->newAccount($customer, $templateType, $redirectUrl, $customer->getStoreId());
980-
$customer->setConfirmation(null);
981980
} catch (MailException $e) {
982981
// If we are not able to send a new account email, this should be ignored
983982
$this->logger->critical($e);
@@ -1615,37 +1614,6 @@ private function getEmailNotification()
16151614
}
16161615
}
16171616

1618-
/**
1619-
* Destroy all active customer sessions by customer id (current session will not be destroyed).
1620-
*
1621-
* Customer sessions which should be deleted are collecting from the "customer_visitor" table considering
1622-
* configured session lifetime.
1623-
*
1624-
* @param string|int $customerId
1625-
* @return void
1626-
*/
1627-
private function destroyCustomerSessions($customerId)
1628-
{
1629-
$this->sessionManager->regenerateId();
1630-
$sessionLifetime = $this->scopeConfig->getValue(
1631-
\Magento\Framework\Session\Config::XML_PATH_COOKIE_LIFETIME,
1632-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
1633-
);
1634-
$dateTime = $this->dateTimeFactory->create();
1635-
$activeSessionsTime = $dateTime->setTimestamp($dateTime->getTimestamp() - $sessionLifetime)
1636-
->format(DateTime::DATETIME_PHP_FORMAT);
1637-
/** @var \Magento\Customer\Model\ResourceModel\Visitor\Collection $visitorCollection */
1638-
$visitorCollection = $this->visitorCollectionFactory->create();
1639-
$visitorCollection->addFieldToFilter('customer_id', $customerId);
1640-
$visitorCollection->addFieldToFilter('last_visit_at', ['from' => $activeSessionsTime]);
1641-
$visitorCollection->addFieldToFilter('session_id', ['neq' => $this->sessionManager->getSessionId()]);
1642-
/** @var \Magento\Customer\Model\Visitor $visitor */
1643-
foreach ($visitorCollection->getItems() as $visitor) {
1644-
$sessionId = $visitor->getSessionId();
1645-
$this->saveHandler->destroy($sessionId);
1646-
}
1647-
}
1648-
16491617
/**
16501618
* Set ignore_validation_flag for reset password flow to skip unnecessary address and customer validation
16511619
*
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Model;
8+
9+
use Magento\Customer\Api\Data\CustomerInterface;
10+
11+
/**
12+
* Account Management service implementation for external API access.
13+
* Handle various customer account actions.
14+
*
15+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
16+
*/
17+
class AccountManagementApi extends AccountManagement
18+
{
19+
/**
20+
* @inheritDoc
21+
*
22+
* Override createAccount method to unset confirmation attribute for security purposes.
23+
*/
24+
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '')
25+
{
26+
$customer = parent::createAccount($customer, $password, $redirectUrl);
27+
$customer->setConfirmation(null);
28+
29+
return $customer;
30+
}
31+
}

app/code/Magento/Customer/etc/graphql/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
</argument>
1717
</arguments>
1818
</type>
19+
<preference for="Magento\Customer\Api\AccountManagementInterface"
20+
type="Magento\Customer\Model\AccountManagementApi" />
1921
</config>

app/code/Magento/Customer/etc/webapi_rest/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@
3131
</argument>
3232
</arguments>
3333
</type>
34+
<preference for="Magento\Customer\Api\AccountManagementInterface"
35+
type="Magento\Customer\Model\AccountManagementApi" />
3436
</config>

app/code/Magento/Customer/etc/webapi_soap/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
</argument>
1919
</arguments>
2020
</type>
21+
<preference for="Magento\Customer\Api\AccountManagementInterface"
22+
type="Magento\Customer\Model\AccountManagementApi" />
2123
</config>

0 commit comments

Comments
 (0)