userExpirationManager = $userExpirationManager; $this->userFactory = $userFactory; } /** * Check for expired user when logging in. * * @param Observer $observer * @return void * @throws AuthenticationException */ public function execute(Observer $observer) { $username = $observer->getEvent()->getUsername(); $user = $this->userFactory->create(); /** @var \Magento\User\Model\User $user */ $user->loadByUsername($username); if ($user->getId() && $this->userExpirationManager->isUserExpired($user->getId())) { $this->userExpirationManager->deactivateExpiredUsersById([$user->getId()]); throw new AuthenticationException( __( 'The account sign-in was incorrect or your account is disabled temporarily. ' . 'Please wait and try again later.' ) ); } } }