1
0
mirror of https://github.com/flarum/core.git synced 2025-10-17 17:56:14 +02:00

Allow/disallow signup per config

This commit is contained in:
Toby Zerner
2015-08-05 18:19:26 +09:30
parent 023eff95e3
commit 4c06e78b57
4 changed files with 30 additions and 14 deletions

View File

@@ -3,22 +3,33 @@
use Flarum\Core\Users\User;
use Flarum\Events\UserWillBeSaved;
use Flarum\Core\Support\DispatchesEvents;
use Flarum\Core\Settings\SettingsRepository;
use Flarum\Core\Exceptions\PermissionDeniedException;
class RegisterUserHandler
{
use DispatchesEvents;
protected $settings;
public function __construct(SettingsRepository $settings)
{
$this->settings = $settings;
}
/**
* @param RegisterUser $command
* @return User
*/
public function handle(RegisterUser $command)
{
if (! $this->settings->get('allow_sign_up')) {
throw new PermissionDeniedException;
}
$actor = $command->actor;
$data = $command->data;
// TODO: check whether or not registration is open (config)
$user = User::register(
array_get($data, 'attributes.username'),
array_get($data, 'attributes.email'),