Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #14895 - Change Password warning message appear two times #14897

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/code/Magento/User/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class User extends AbstractModel implements StorageInterface, UserInterface
/** @deprecated */
const XML_PATH_RESET_PASSWORD_TEMPLATE = 'admin/emails/reset_password_template';

const MESSAGE_ID_PASSWORD_EXPIRED = 'magento_user_password_expired';

/**
* Model event prefix
*
Expand Down
12 changes: 9 additions & 3 deletions app/code/Magento/User/Observer/Backend/AuthObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function execute(EventObserver $observer)
/**
* Update locking information for the user
*
* @param \Magento\User\Model\User $user
* @param User $user
* @return void
*/
private function _updateLockingInformation($user)
Expand Down Expand Up @@ -198,10 +198,16 @@ private function _checkExpiredPassword($latestPassword)
$myAccountUrl = $this->url->getUrl('adminhtml/system_account/');
$message = __('It\'s time to <a href="%1">change your password</a>.', $myAccountUrl);
}

$messages = $this->messageManager->getMessages();

// Remove existing messages with same ID to avoid duplication
$messages->deleteMessageByIdentifier(User::MESSAGE_ID_PASSWORD_EXPIRED);

$this->messageManager->addNoticeMessage($message);
$message = $this->messageManager->getMessages()->getLastAddedMessage();
$message = $messages->getLastAddedMessage();
if ($message) {
$message->setIdentifier('magento_user_password_expired')->setIsSticky(true);
$message->setIdentifier(User::MESSAGE_ID_PASSWORD_EXPIRED)->setIsSticky(true);
$this->authSession->setPciAdminUserIsPasswordExpired(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
use Magento\User\Model\User;

/**
* User backend observer model for passwords
Expand Down Expand Up @@ -74,7 +75,7 @@ public function execute(EventObserver $observer)
$passwordHash = $user->getPassword();
if ($passwordHash && !$user->getForceNewPassword()) {
$this->userResource->trackPassword($user, $passwordHash);
$this->messageManager->getMessages()->deleteMessageByIdentifier('magento_user_password_expired');
$this->messageManager->getMessages()->deleteMessageByIdentifier(User::MESSAGE_ID_PASSWORD_EXPIRED);
$this->authSession->unsPciAdminUserIsPasswordExpired();
}
}
Expand Down