From c4c51ea044eef8cd9d8346ab241105af179eec7d Mon Sep 17 00:00:00 2001 From: IrinaZhadzinets Date: Thu, 19 May 2022 15:40:28 +0300 Subject: [PATCH 1/2] #3243 - Reset confirmation when reset password --- src/Model/Resolver/ResetPassword.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Model/Resolver/ResetPassword.php b/src/Model/Resolver/ResetPassword.php index 2131949..e0430c3 100644 --- a/src/Model/Resolver/ResetPassword.php +++ b/src/Model/Resolver/ResetPassword.php @@ -13,6 +13,7 @@ namespace ScandiPWA\CustomerGraphQl\Model\Resolver; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\InputException; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlInputException; @@ -20,6 +21,7 @@ use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Customer\Model\Session; use Magento\Customer\Api\AccountManagementInterface; +use Magento\Customer\Model\ForgotPasswordToken\ConfirmCustomerByToken; class ResetPassword implements ResolverInterface { const STATUS_PASSWORDS_MISS_MATCH = 'passwords_miss_match'; @@ -36,12 +38,25 @@ class ResetPassword implements ResolverInterface { */ protected $session; + /** + * @var ConfirmCustomerByToken + */ + protected ConfirmCustomerByToken $confirmByToken; + + /** + * @param Session $customerSession + * @param AccountManagementInterface $accountManagement + * @param ConfirmCustomerByToken|null $confirmByToken + */ public function __construct( Session $customerSession, - AccountManagementInterface $accountManagement + AccountManagementInterface $accountManagement, + ConfirmCustomerByToken $confirmByToken = null ) { $this->session = $customerSession; $this->accountManagement = $accountManagement; + $this->confirmByToken = $confirmByToken + ?? ObjectManager::getInstance()->get(ConfirmCustomerByToken::class); } /** @@ -73,8 +88,13 @@ public function resolve( } try { + // Check if the user has not yet confirmed the account + // and if not do this along with changing the password + $this->confirmByToken->execute($resetPasswordToken); + $this->accountManagement->resetPassword(null, $resetPasswordToken, $password); $this->session->unsRpToken(); + return [ 'status' => self::STATUS_PASSWORD_UPDATED ]; } catch (InputException $e) { throw new GraphQlInputException(__($e->getMessage())); From c37915ec8ecc03c610ba1e2f225a439f65393937 Mon Sep 17 00:00:00 2001 From: IrinaZhadzinets Date: Fri, 10 Jun 2022 16:09:36 +0300 Subject: [PATCH 2/2] #3243 - Remove object manager --- src/Model/Resolver/ResetPassword.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Model/Resolver/ResetPassword.php b/src/Model/Resolver/ResetPassword.php index bafa9e3..a06693b 100644 --- a/src/Model/Resolver/ResetPassword.php +++ b/src/Model/Resolver/ResetPassword.php @@ -14,7 +14,6 @@ namespace ScandiPWA\CustomerGraphQl\Model\Resolver; use Magento\Customer\Api\CustomerRepositoryInterface; -use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\InputException; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Exception\GraphQlInputException; @@ -66,8 +65,7 @@ public function __construct( $this->session = $customerSession; $this->accountManagement = $accountManagement; $this->customerRepository = $customerRepository; - $this->confirmByToken = $confirmByToken - ?? ObjectManager::getInstance()->get(ConfirmCustomerByToken::class); + $this->confirmByToken = $confirmByToken; } /**