mirror of
https://github.com/flarum/core.git
synced 2025-08-18 22:31:32 +02:00
Allow/disallow signup per config
This commit is contained in:
@@ -30,7 +30,8 @@ class ForumSerializer extends Serializer
|
||||
'welcomeMessage' => Core::config('welcome_message'),
|
||||
'themePrimaryColor' => Core::config('theme_primary_color'),
|
||||
'canView' => $forum->can($this->actor, 'view'),
|
||||
'canStartDiscussion' => $forum->can($this->actor, 'startDiscussion')
|
||||
'canStartDiscussion' => $forum->can($this->actor, 'startDiscussion'),
|
||||
'allowSignUp' => (bool) Core::config('allow_sign_up')
|
||||
];
|
||||
|
||||
if ($this->actor->isAdmin()) {
|
||||
|
@@ -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'),
|
||||
|
Reference in New Issue
Block a user