Justoverclock have you looked at the Middleware section of the Flarum docs? I can probably whip up a POC, but you can also take a look at how Pwned Passwords did it with the password field š
Edit: Here is a basic Middleware example I created based off the Pwned Passwords extension; I was in a bit of a rush so I only used a single value for comparison, but ultimately you should be able to store a list of blacklisted usernames in the settings table and compare those values to what is being submitted when the user tries to register.
<?php
namespace Ralkage\DrawingBoard\Middleware;
use Flarum\Foundation\ErrorHandling\JsonApiFormatter;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ValidationException;
use Flarum\Http\UrlGenerator;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Uri;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
class PreventBlacklistedUsernames implements MiddlewareInterface
{
/**
* @var UrlGenerator
*/
private UrlGenerator $url;
public function __construct(UrlGenerator $url)
{
$this->url = $url;
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$data = $request->getParsedBody();
$uri = new Uri($this->url->to('forum')->path('/register'));
$path = $request->getUri()->getPath();
$blackListedUsernameExample = 'Ral';
if ($request->getMethod() === 'POST' && $uri->getPath() === $path && Arr::has($data, 'username')
&& $data['username'] === $blackListedUsernameExample) {
return (new JsonApiFormatter())->format(
resolve(Registry::class)->handle(
new ValidationException(['username' => 'This username cannot be used.'])
),
$request
);
}
return $handler->handle($request);
}
}
Not the perfect example, but that should handle the server-side validation š