From 8d254c12f6ea838fa17199481a9f1486a2ddef4d Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 5 Aug 2015 18:19:26 +0930 Subject: [PATCH] Allow/disallow signup per config --- .../js/forum/src/components/HeaderSecondary.js | 16 +++++++++------- .../core/js/forum/src/components/LogInModal.js | 10 ++++++---- .../core/src/Api/Serializers/ForumSerializer.php | 3 ++- .../Core/Users/Commands/RegisterUserHandler.php | 15 +++++++++++++-- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/framework/core/js/forum/src/components/HeaderSecondary.js b/framework/core/js/forum/src/components/HeaderSecondary.js index 1146e93a4..43d7a69a4 100644 --- a/framework/core/js/forum/src/components/HeaderSecondary.js +++ b/framework/core/js/forum/src/components/HeaderSecondary.js @@ -35,13 +35,15 @@ export default class HeaderSecondary extends Component { items.add('notifications', NotificationsDropdown.component()); items.add('session', SessionDropdown.component()); } else { - items.add('signUp', - Button.component({ - children: app.trans('core.sign_up'), - className: 'Button Button--link', - onclick: () => app.modal.show(new SignUpModal()) - }) - ); + if (app.forum.attribute('allowSignUp')) { + items.add('signUp', + Button.component({ + children: app.trans('core.sign_up'), + className: 'Button Button--link', + onclick: () => app.modal.show(new SignUpModal()) + }) + ); + } items.add('logIn', Button.component({ diff --git a/framework/core/js/forum/src/components/LogInModal.js b/framework/core/js/forum/src/components/LogInModal.js index 54c9f87f5..ab4818d32 100644 --- a/framework/core/js/forum/src/components/LogInModal.js +++ b/framework/core/js/forum/src/components/LogInModal.js @@ -71,10 +71,12 @@ export default class LogInModal extends Modal {

{app.trans('core.forgot_password_link')}

-

- {app.trans('core.before_sign_up_link')}{' '} - {app.trans('core.sign_up')} -

+ {app.forum.attribute('allowSignUp') ? ( +

+ {app.trans('core.before_sign_up_link')}{' '} + {app.trans('core.sign_up')} +

+ ) : ''} ]; } diff --git a/framework/core/src/Api/Serializers/ForumSerializer.php b/framework/core/src/Api/Serializers/ForumSerializer.php index 67c8708d6..41ec3d662 100644 --- a/framework/core/src/Api/Serializers/ForumSerializer.php +++ b/framework/core/src/Api/Serializers/ForumSerializer.php @@ -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()) { diff --git a/framework/core/src/Core/Users/Commands/RegisterUserHandler.php b/framework/core/src/Core/Users/Commands/RegisterUserHandler.php index f96c18fc6..d290c9d39 100644 --- a/framework/core/src/Core/Users/Commands/RegisterUserHandler.php +++ b/framework/core/src/Core/Users/Commands/RegisterUserHandler.php @@ -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'),