how to overwrite UserValidator.php or make custom user validation extension.
<?php
namespace Jubayed\UserValidator;
use Flarum\Core\Validator\AbstractValidator;
class UserValidator extends AbstractValidator
{
protected $rules = [
'username' => [
'required',
'regex:/^[ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣ০১২৩৪৫৬৭৮৯ৰৱ৲৳৴৵৶৷৸৹৺৻_-]+$/i',
'min:3',
'max:30'
],
'email' => [
'required',
'email',
],
'password' => [
'required',
'min:8'
]
];
}
and
<?php
namespace Jubayed\UserValidator\Listener;
use Illuminate\Contracts\Events\Dispatcher;
use Flarum\Event\ConfigureValidator;
use Flarum\Settings\SettingsRepositoryInterface;
use Jubayed\UserValidator\UserValidator;
class AddValidatorRule {
/**
* @var SettingsRepositoryInterface
*/
protected $settings;
/**
* @param SettingsRepositoryInterface $settings
*/
public function __construct(SettingsRepositoryInterface $settings)
{
//$this->settings = $settings;
}
public function subscribe(Dispatcher $events)
{
$events->listen(ConfigureValidator::class, [$this, 'addRule']);
}
public function addRule(ConfigureValidator $event) {
if ($event->type instanceof UserValidator) {
$event->validator->addReplacers(['username','email','password']);
}
}
}