Add PoC event listeners for authentication events
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 17 Feb 2021 10:34:19 +0000 (11:34 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 7 Jun 2021 11:51:06 +0000 (13:51 +0200)
com.woltlab.wcf/eventListener.xml
wcfsetup/install/files/lib/system/event/listener/UserLoggedInEmailNotificationListener.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/event/listener/UserMultifactorSucceededEmailNotificationListener.class.php [new file with mode: 0644]

index e7beec0941fe1e491392ad17104ec35cfce71b71..a3fddcea1aa26e5df40e38b5c2c07766115817dd 100644 (file)
                        <listenerclassname>wcf\system\event\listener\UserLinkHtmlInputNodeProcessorListener</listenerclassname>
                        <environment>all</environment>
                </eventlistener>
+               <eventlistener name="userLoggedInEmailNotification">
+                       <eventclassname>wcf\system\user\authentication\UserLoggedIn</eventclassname>
+                       <eventname>:default</eventname>
+                       <listenerclassname>wcf\system\event\listener\UserLoggedInEmailNotificationListener</listenerclassname>
+                       <environment>all</environment>
+               </eventlistener>
+               <eventlistener name="userMultifactorSucceededEmailNotification">
+                       <eventclassname>wcf\system\user\authentication\UserMultifactorSucceeded</eventclassname>
+                       <eventname>:default</eventname>
+                       <listenerclassname>wcf\system\event\listener\UserMultifactorSucceededEmailNotificationListener</listenerclassname>
+                       <environment>all</environment>
+               </eventlistener>
        </import>
 </data>
diff --git a/wcfsetup/install/files/lib/system/event/listener/UserLoggedInEmailNotificationListener.class.php b/wcfsetup/install/files/lib/system/event/listener/UserLoggedInEmailNotificationListener.class.php
new file mode 100644 (file)
index 0000000..7d8ce06
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace wcf\system\event\listener;
+
+use wcf\system\email\SimpleEmail;
+use wcf\system\user\authentication\UserLoggedIn;
+
+/**
+ * Sends a notification email when the user 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
+ */
+final class UserLoggedInEmailNotificationListener implements IParameterizedEventListener
+{
+    /**
+     * @inheritDoc
+     * @param UserLoggedIn $eventObj
+     */
+    public function execute($eventObj, $className, $eventName, array &$parameters)
+    {
+        $email = new SimpleEmail();
+        $email->setRecipient($eventObj->getUser());
+        $email->setSubject("You logged in");
+        $email->setMessage("You logged in");
+        $email->setHtmlMessage("You logged in");
+        $email->send();
+    }
+}
diff --git a/wcfsetup/install/files/lib/system/event/listener/UserMultifactorSucceededEmailNotificationListener.class.php b/wcfsetup/install/files/lib/system/event/listener/UserMultifactorSucceededEmailNotificationListener.class.php
new file mode 100644 (file)
index 0000000..17cac35
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace wcf\system\event\listener;
+
+use wcf\system\email\SimpleEmail;
+use wcf\system\user\authentication\UserMultifactorSucceeded;
+
+/**
+ * Sends a notification email when the user performs MF authentication.
+ *
+ * @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
+ */
+final class UserMultifactorSucceededEmailNotificationListener implements IParameterizedEventListener
+{
+    /**
+     * @inheritDoc
+     * @param UserMultifactorSucceeded $eventObj
+     */
+    public function execute($eventObj, $className, $eventName, array &$parameters)
+    {
+        $email = new SimpleEmail();
+        $email->setRecipient($eventObj->getUser());
+        $email->setSubject("You performed MFA with {$eventObj->getSetup()->getObjectType()->objectType}");
+        $email->setMessage("You performed MFA with {$eventObj->getSetup()->getObjectType()->objectType}");
+        $email->setHtmlMessage("You performed MFA with {$eventObj->getSetup()->getObjectType()->objectType}");
+        $email->send();
+    }
+}