Cancel lost password requests when the user logs in
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 1 Jul 2021 12:59:02 +0000 (14:59 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 2 Jul 2021 09:24:51 +0000 (11:24 +0200)
Resolves #3922

com.woltlab.wcf/eventListener.xml
wcfsetup/install/files/lib/system/event/listener/UserLoginCancelLostPasswordListener.class.php [new file with mode: 0644]

index 3fb2f656d55517ee6bbe00674d5f9e5616d99625..20179f8bdef4714aafef8f809a5cf1c1ff64d25c 100644 (file)
                        <listenerclassname>wcf\system\event\listener\UserLinkHtmlInputNodeProcessorListener</listenerclassname>
                        <environment>all</environment>
                </eventlistener>
+               <eventlistener name="userLoginCancelLostPassword">
+                       <eventclassname>wcf\system\user\authentication\event\UserLoggedIn</eventclassname>
+                       <listenerclassname>wcf\system\event\listener\UserLoginCancelLostPasswordListener</listenerclassname>
+                       <environment>all</environment>
+               </eventlistener>
        </import>
 </data>
diff --git a/wcfsetup/install/files/lib/system/event/listener/UserLoginCancelLostPasswordListener.class.php b/wcfsetup/install/files/lib/system/event/listener/UserLoginCancelLostPasswordListener.class.php
new file mode 100644 (file)
index 0000000..2ce062d
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace wcf\system\event\listener;
+
+use wcf\data\user\UserAction;
+use wcf\system\user\authentication\event\UserLoggedIn;
+
+/**
+ * Cancels lost password requests if the user successfully logs in.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Event\Listener
+ * @since   5.5
+ */
+final class UserLoginCancelLostPasswordListener
+{
+    public function __invoke(UserLoggedIn $event)
+    {
+        $user = $event->getUser();
+        if (!$user->lostPasswordKey) {
+            return;
+        }
+
+        (new UserAction(
+            [$user],
+            'update',
+            [
+                'data' => [
+                    'lastLostPasswordRequestTime' => 0,
+                    'lostPasswordKey' => '',
+                ],
+            ]
+        ))->executeAction();
+    }
+}