Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/classes/Core/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,6 @@ private function getMessage(string $field, string $rule, string $fallback, ?arra
*/
public function passed(): bool
{
return $this->_passed;
return $this->_passed && !count($this->errors());
}
}
16 changes: 16 additions & 0 deletions modules/Core/classes/Events/PreUserRegistrationEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

class PreUserRegistrationEvent extends AbstractEvent {

use Cancellable;

public array $data;

public function __construct(array $data) {
$this->data = $data;
}

public static function internal(): bool {
return true;
}
}
1 change: 1 addition & 0 deletions modules/Core/classes/Misc/CoreApiErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ class CoreApiErrors {
public const ERROR_WEBHOOK_URL_INCORRECT_LENGTH = 'core:webhook_url_incorrect_length';
public const ERROR_WEBHOOK_INVALID_TYPE = 'core:webhook_type_invalid';
public const ERROR_WEBHOOK_INVALID_EVENT = 'core:webhook_event_invalid';
public const ERROR_EVENT_CANCELLED = 'core:event_cancelled';
}
7 changes: 7 additions & 0 deletions modules/Core/includes/endpoints/RegisterEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public function execute(Nameless2API $api): void {
$api->throwError(CoreApiErrors::ERROR_USERNAME_ALREADY_EXISTS);
}

$pre_registration_event = EventHandler::executeEvent(new PreUserRegistrationEvent(
$_POST,
));
if ($pre_registration_event->isCancelled()) {
$api->throwError(CoreApiErrors::ERROR_EVENT_CANCELLED, $pre_registration_event->getCancelledReason());
}

// Integrations
if (isset($_POST['integrations'])) {
$integrations = Integrations::getInstance();
Expand Down
1 change: 1 addition & 0 deletions modules/Core/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public function __construct(Language $language, Pages $pages, User $user, Naviga
EventHandler::registerEvent(UserWarnedEvent::class);

// -- Pipelines
EventHandler::registerEvent(PreUserRegistrationEvent::class);
EventHandler::registerEvent(PreCustomPageCreateEvent::class);
EventHandler::registerEvent(PreCustomPageEditEvent::class);
EventHandler::registerEvent(RenderContentEvent::class);
Expand Down
8 changes: 8 additions & 0 deletions modules/Core/pages/authme_connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
},
]);

$pre_registration_event = EventHandler::executeEvent(new PreUserRegistrationEvent(
$_POST,
));

if ($pre_registration_event->isCancelled()) {
$validation->addCustomError('custom', $pre_registration_event->getCancelledReason());
}

if ($validation->passed()) {
// Get default language ID before creating user
$language_id = DB::getInstance()->get('languages', ['short_code', LANGUAGE]);
Expand Down
8 changes: 8 additions & 0 deletions modules/Core/pages/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@
Redirect::to(URL::build('/'));
}

$pre_registration_event = EventHandler::executeEvent(new PreUserRegistrationEvent(
$_POST,
));

if ($pre_registration_event->isCancelled()) {
$validation->addCustomError('custom', $pre_registration_event->getCancelledReason());
}

// Check if any integrations wanna modify the validation
foreach ($integrations->getEnabledIntegrations() as $integration) {
$integration->beforeRegistrationValidation($validation);
Expand Down