Allow/disallow signup per config

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

View File

@ -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({

View File

@ -71,10 +71,12 @@ export default class LogInModal extends Modal {
<p className="LogInModal-forgotPassword">
<a onclick={this.forgotPassword.bind(this)}>{app.trans('core.forgot_password_link')}</a>
</p>
<p className="LogInModal-signUp">
{app.trans('core.before_sign_up_link')}{' '}
<a onclick={this.signUp.bind(this)}>{app.trans('core.sign_up')}</a>
</p>
{app.forum.attribute('allowSignUp') ? (
<p className="LogInModal-signUp">
{app.trans('core.before_sign_up_link')}{' '}
<a onclick={this.signUp.bind(this)}>{app.trans('core.sign_up')}</a>
</p>
) : ''}
</div>
];
}

View File

@ -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()) {

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'),