Skip to content

Commit 33834ab

Browse files
MC-39757: Email to reset admin password shows "Your password reset link has expired", when using custom template
1 parent 9faf621 commit 33834ab

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

app/code/Magento/User/view/adminhtml/email/password_reset_confirmation.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"var user.id":"Account Holder Id",
1111
"var user.rp_token":"Reset Password Token",
1212
"var user.name":"Account Holder Name",
13-
"store url=\"admin\/auth\/resetpassword\/\" _query_id=$user.id _query_token=$user.rp_token":"Reset Password URL",
13+
"store url=\"admin\/auth\/resetpassword\/\" _query_id=$user.user_id _query_token=$user.rp_token":"Reset Password URL",
1414
"var username":"Account Holder Name"
1515
} @-->
1616

@@ -20,7 +20,7 @@
2020

2121
{{trans "If you requested this change, reset your password here:"}}
2222

23-
{{store url="admin/auth/resetpassword/" _query_id=$user.id _query_token=$user.rp_token _nosid=1}}
23+
{{store url="admin/auth/resetpassword/" _query_id=$user.user_id _query_token=$user.rp_token _nosid=1}}
2424

2525
{{trans "If you did not make this request, you can ignore this email and your password will remain the same."}}
2626

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
$origTemplateCode = 'admin_emails_forgot_email_template';
9+
/** @var \Magento\Email\Model\Template $template */
10+
$template = $objectManager->create(\Magento\Email\Model\Template::class);
11+
$template->loadDefault($origTemplateCode);
12+
$template->setTemplateCode('Reset Password User Notification Custom Code');
13+
$template->setOrigTemplateCode('admin_emails_forgot_email_template');
14+
$template->setId(null);
15+
$template->save();

dev/tests/integration/testsuite/Magento/User/Model/UserTest.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,9 @@ public function testSendNotificationEmailsIfRequired()
591591
->get(MutableScopeConfigInterface::class);
592592
$config->setValue(
593593
'admin/emails/new_user_notification_template',
594-
$this->getCustomEmailTemplateIdForNewUserNotification()
594+
$this->getCustomEmailTemplateIdForNewUserNotification(
595+
'admin_emails_new_user_notification_template'
596+
)
595597
);
596598
$userModel = Bootstrap::getObjectManager()
597599
->create(User::class);
@@ -621,15 +623,15 @@ public function testSendNotificationEmailsIfRequired()
621623
/**
622624
* Return email template id for new user notification
623625
*
626+
* @param string $origTemplateCode
624627
* @return int|null
625628
* @throws NotFoundException
626629
*/
627-
private function getCustomEmailTemplateIdForNewUserNotification(): ?int
630+
private function getCustomEmailTemplateIdForNewUserNotification(string $origTemplateCode): ?int
628631
{
629632
$templateId = null;
630633
$templateCollection = Bootstrap::getObjectManager()
631634
->get(TemplateCollection::class);
632-
$origTemplateCode = 'admin_emails_new_user_notification_template';
633635
foreach ($templateCollection as $template) {
634636
if ($template->getOrigTemplateCode() == $origTemplateCode) {
635637
$templateId = (int) $template->getId();
@@ -643,4 +645,33 @@ private function getCustomEmailTemplateIdForNewUserNotification(): ?int
643645
}
644646
return $templateId;
645647
}
648+
649+
/**
650+
* Verify custom notification is correctly when reset admin password
651+
*
652+
* @magentoDataFixture Magento/Email/Model/_files/email_template_reset_password_user_notification.php
653+
* @magentoDataFixture Magento/User/_files/user_with_role.php
654+
*/
655+
public function testNotificationEmailsIfResetPassword()
656+
{
657+
/** @var MutableScopeConfigInterface $config */
658+
$config = Bootstrap::getObjectManager()
659+
->get(MutableScopeConfigInterface::class);
660+
$config->setValue(
661+
'admin/emails/forgot_email_template',
662+
$this->getCustomEmailTemplateIdForNewUserNotification(
663+
'admin_emails_forgot_email_template'
664+
)
665+
);
666+
$userModel = $this->_model->loadByUsername('adminUser');
667+
$notificator = $this->objectManager->get(\Magento\User\Model\Spi\NotificatorInterface::class);
668+
$notificator->sendForgotPassword($userModel);
669+
/** @var TransportBuilderMock $transportBuilderMock */
670+
$transportBuilderMock = $this->objectManager->get(TransportBuilderMock::class);
671+
$sentMessage = $transportBuilderMock->getSentMessage();
672+
$this->assertStringContainsString(
673+
'id='.$userModel->getId(),
674+
quoted_printable_decode($sentMessage->getBodyText())
675+
);
676+
}
646677
}

0 commit comments

Comments
 (0)