mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 18:12:59 +08:00
Allow/disallow signup per config
This commit is contained in:
parent
c6d0bc85f6
commit
8d254c12f6
|
@ -35,6 +35,7 @@ export default class HeaderSecondary extends Component {
|
|||
items.add('notifications', NotificationsDropdown.component());
|
||||
items.add('session', SessionDropdown.component());
|
||||
} else {
|
||||
if (app.forum.attribute('allowSignUp')) {
|
||||
items.add('signUp',
|
||||
Button.component({
|
||||
children: app.trans('core.sign_up'),
|
||||
|
@ -42,6 +43,7 @@ export default class HeaderSecondary extends Component {
|
|||
onclick: () => app.modal.show(new SignUpModal())
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
items.add('logIn',
|
||||
Button.component({
|
||||
|
|
|
@ -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>
|
||||
{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>
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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'),
|
||||
|
|
Loading…
Reference in New Issue
Block a user