-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5929 from WoltLab/spam-checking-event
Use an event for the spam check during registration
- Loading branch information
Showing
16 changed files
with
326 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
wcfsetup/install/files/lib/event/message/MessageSpamChecking.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace wcf\event\message; | ||
|
||
use wcf\data\user\User; | ||
use wcf\event\IInterruptableEvent; | ||
use wcf\event\TInterruptableEvent; | ||
use wcf\system\html\input\HtmlInputProcessor; | ||
|
||
/** | ||
* Indicates that a new message by a user is currently validated. If this event is interrupted, | ||
* the message is considered to be spam. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.1 | ||
*/ | ||
final class MessageSpamChecking implements IInterruptableEvent | ||
{ | ||
use TInterruptableEvent; | ||
|
||
public function __construct( | ||
public readonly HtmlInputProcessor $processor, | ||
public readonly ?User $user = null, | ||
public readonly string $ipAddress = '', | ||
public readonly string $subject = '', | ||
) { | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
wcfsetup/install/files/lib/event/page/ContactFormSpamChecking.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace wcf\event\page; | ||
|
||
use wcf\event\IInterruptableEvent; | ||
use wcf\event\TInterruptableEvent; | ||
|
||
/** | ||
* Indicates that a new contact form message is currently validated. If this event is interrupted, | ||
* the message is considered to be spam. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.1 | ||
*/ | ||
final class ContactFormSpamChecking implements IInterruptableEvent | ||
{ | ||
use TInterruptableEvent; | ||
|
||
public function __construct( | ||
public readonly string $email, | ||
public readonly string $ipAddress, | ||
public readonly array $messages, | ||
) { | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
wcfsetup/install/files/lib/event/user/RegistrationSpamChecking.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace wcf\event\user; | ||
|
||
use wcf\event\IPsr14Event; | ||
|
||
/** | ||
* 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 | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.1 | ||
*/ | ||
final class RegistrationSpamChecking implements IPsr14Event | ||
{ | ||
private array $matches = []; | ||
|
||
public function __construct( | ||
public readonly string $username, | ||
public readonly string $email, | ||
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.