Add UsernameValidating event
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 20 Apr 2023 15:25:55 +0000 (17:25 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 20 Apr 2023 15:32:20 +0000 (17:32 +0200)
wcfsetup/install/files/lib/system/user/event/UsernameValidating.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/util/UserRegistrationUtil.class.php

diff --git a/wcfsetup/install/files/lib/system/user/event/UsernameValidating.class.php b/wcfsetup/install/files/lib/system/user/event/UsernameValidating.class.php
new file mode 100644 (file)
index 0000000..c14f1d2
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+namespace wcf\system\user\event;
+
+use wcf\system\event\IInterruptableEvent;
+use wcf\system\event\TInterruptableEvent;
+
+/**
+ * Indicates that a username is currently validated. If this event
+ * is interrupted, the username is considered to be invalid.
+ * 
+ * This event will not be fired for usernames changed by an administrator.
+ *
+ * @author Tim Duesterhus
+ * @copyright 2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.0
+ */
+final class UsernameValidating implements IInterruptableEvent
+{
+    use TInterruptableEvent;
+
+    public function __construct(
+        public readonly string $username
+    ) {
+    }
+}
index bf7c5829c1b0fe377a481e0dc280a75f861006c8..42b734a915a1a716bc70ebef0edce76c86877f6e 100644 (file)
@@ -3,6 +3,8 @@
 namespace wcf\util;
 
 use Spoofchecker;
+use wcf\system\event\EventHandler;
+use wcf\system\user\event\UsernameValidating;
 
 /**
  * Contains user registration related functions.
@@ -39,6 +41,12 @@ final class UserRegistrationUtil
             return false;
         }
 
+        $event = new UsernameValidating($name);
+        EventHandler::getInstance()->fire($event);
+        if ($event->defaultPrevented()) {
+            return false;
+        }
+
         switch (REGISTER_USERNAME_FORCE_ASCII) {
             case 0:
                 break;