namespace wcf\event\user;
-use wcf\event\IInterruptableEvent;
-use wcf\event\TInterruptableEvent;
+use wcf\event\IPsr14Event;
/**
- * Indicates that a registration by a new user is currently validated. If this event is interrupted,
+ * Indicates that a registration by a new user is currently validated. If $matches is not empty,
* the registration is considered to be a spammer or an undesirable user.
*
* @author Marcel Werk
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.1
*/
-final class RegistrationSpamChecking implements IInterruptableEvent
+final class RegistrationSpamChecking implements IPsr14Event
{
- use TInterruptableEvent;
+ private array $matches = [];
public function __construct(
public readonly string $username,
public readonly string $ipAddress
) {
}
+
+ public function hasMatches(): bool
+ {
+ return $this->matches !== [];
+ }
+
+ public function addMatch(string $key): void
+ {
+ $this->matches[$key] = $key;
+ }
+
+ public function getMatches(): array
+ {
+ return \array_values($this->matches);
+ }
}
$this->spamCheckEvent = new RegistrationSpamChecking($this->username, $this->email, UserUtil::getIpAddress());
EventHandler::getInstance()->fire($this->spamCheckEvent);
- if ($this->spamCheckEvent->defaultPrevented() && \REGISTER_ANTISPAM_ACTION === 'block') {
+ if ($this->spamCheckEvent->hasMatches() && \REGISTER_ANTISPAM_ACTION === 'block') {
throw new NamedUserException(
WCF::getLanguage()->getDynamicVariable('wcf.user.register.error.blacklistMatches')
);
// generate activation code
$addDefaultGroups = true;
if (
- $this->spamCheckEvent->defaultPrevented()
+ $this->spamCheckEvent->hasMatches()
|| (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER && !$registerVia3rdParty)
|| (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN)
) {
'username' => $this->username,
'email' => $this->email,
'password' => $this->password,
+ 'blacklistMatches' => $this->spamCheckEvent->hasMatches() ? JSON::encode($this->spamCheckEvent->getMatches()) : '',
'signatureEnableHtml' => 1,
]),
'groups' => $this->groupIDs,
WCF::getSession()->changeUser($user);
// activation management
- if (REGISTER_ACTIVATION_METHOD == User::REGISTER_ACTIVATION_NONE && !$this->spamCheckEvent->defaultPrevented()) {
+ if (REGISTER_ACTIVATION_METHOD == User::REGISTER_ACTIVATION_NONE && !$this->spamCheckEvent->hasMatches()) {
$this->message = 'wcf.user.register.success';
UserGroupAssignmentHandler::getInstance()->checkUsers([$user->userID]);
- } elseif (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER && !$this->spamCheckEvent->defaultPrevented()) {
+ } elseif (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER && !$this->spamCheckEvent->hasMatches()) {
// registering via 3rdParty leads to instant activation
if ($registerVia3rdParty) {
$this->message = 'wcf.user.register.success';
$email->send();
$this->message = 'wcf.user.register.success.needActivation';
}
- } elseif (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN || $this->spamCheckEvent->defaultPrevented()) {
+ } elseif (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN || $this->spamCheckEvent->hasMatches()) {
$this->message = 'wcf.user.register.success.awaitActivation';
}