mirror of
https://github.com/flarum/framework.git
synced 2025-05-26 00:29:59 +08:00
Allow/disallow signup per config
This commit is contained in:
@ -35,6 +35,7 @@ export default class HeaderSecondary extends Component {
|
|||||||
items.add('notifications', NotificationsDropdown.component());
|
items.add('notifications', NotificationsDropdown.component());
|
||||||
items.add('session', SessionDropdown.component());
|
items.add('session', SessionDropdown.component());
|
||||||
} else {
|
} else {
|
||||||
|
if (app.forum.attribute('allowSignUp')) {
|
||||||
items.add('signUp',
|
items.add('signUp',
|
||||||
Button.component({
|
Button.component({
|
||||||
children: app.trans('core.sign_up'),
|
children: app.trans('core.sign_up'),
|
||||||
@ -42,6 +43,7 @@ export default class HeaderSecondary extends Component {
|
|||||||
onclick: () => app.modal.show(new SignUpModal())
|
onclick: () => app.modal.show(new SignUpModal())
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
items.add('logIn',
|
items.add('logIn',
|
||||||
Button.component({
|
Button.component({
|
||||||
|
@ -71,10 +71,12 @@ export default class LogInModal extends Modal {
|
|||||||
<p className="LogInModal-forgotPassword">
|
<p className="LogInModal-forgotPassword">
|
||||||
<a onclick={this.forgotPassword.bind(this)}>{app.trans('core.forgot_password_link')}</a>
|
<a onclick={this.forgotPassword.bind(this)}>{app.trans('core.forgot_password_link')}</a>
|
||||||
</p>
|
</p>
|
||||||
|
{app.forum.attribute('allowSignUp') ? (
|
||||||
<p className="LogInModal-signUp">
|
<p className="LogInModal-signUp">
|
||||||
{app.trans('core.before_sign_up_link')}{' '}
|
{app.trans('core.before_sign_up_link')}{' '}
|
||||||
<a onclick={this.signUp.bind(this)}>{app.trans('core.sign_up')}</a>
|
<a onclick={this.signUp.bind(this)}>{app.trans('core.sign_up')}</a>
|
||||||
</p>
|
</p>
|
||||||
|
) : ''}
|
||||||
</div>
|
</div>
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,8 @@ class ForumSerializer extends Serializer
|
|||||||
'welcomeMessage' => Core::config('welcome_message'),
|
'welcomeMessage' => Core::config('welcome_message'),
|
||||||
'themePrimaryColor' => Core::config('theme_primary_color'),
|
'themePrimaryColor' => Core::config('theme_primary_color'),
|
||||||
'canView' => $forum->can($this->actor, 'view'),
|
'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()) {
|
if ($this->actor->isAdmin()) {
|
||||||
|
@ -3,22 +3,33 @@
|
|||||||
use Flarum\Core\Users\User;
|
use Flarum\Core\Users\User;
|
||||||
use Flarum\Events\UserWillBeSaved;
|
use Flarum\Events\UserWillBeSaved;
|
||||||
use Flarum\Core\Support\DispatchesEvents;
|
use Flarum\Core\Support\DispatchesEvents;
|
||||||
|
use Flarum\Core\Settings\SettingsRepository;
|
||||||
|
use Flarum\Core\Exceptions\PermissionDeniedException;
|
||||||
|
|
||||||
class RegisterUserHandler
|
class RegisterUserHandler
|
||||||
{
|
{
|
||||||
use DispatchesEvents;
|
use DispatchesEvents;
|
||||||
|
|
||||||
|
protected $settings;
|
||||||
|
|
||||||
|
public function __construct(SettingsRepository $settings)
|
||||||
|
{
|
||||||
|
$this->settings = $settings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RegisterUser $command
|
* @param RegisterUser $command
|
||||||
* @return User
|
* @return User
|
||||||
*/
|
*/
|
||||||
public function handle(RegisterUser $command)
|
public function handle(RegisterUser $command)
|
||||||
{
|
{
|
||||||
|
if (! $this->settings->get('allow_sign_up')) {
|
||||||
|
throw new PermissionDeniedException;
|
||||||
|
}
|
||||||
|
|
||||||
$actor = $command->actor;
|
$actor = $command->actor;
|
||||||
$data = $command->data;
|
$data = $command->data;
|
||||||
|
|
||||||
// TODO: check whether or not registration is open (config)
|
|
||||||
|
|
||||||
$user = User::register(
|
$user = User::register(
|
||||||
array_get($data, 'attributes.username'),
|
array_get($data, 'attributes.username'),
|
||||||
array_get($data, 'attributes.email'),
|
array_get($data, 'attributes.email'),
|
||||||
|
Reference in New Issue
Block a user