1
0
mirror of https://github.com/flarum/core.git synced 2025-10-17 09:46:14 +02:00
Files
php-flarum/src/Core/Handlers/Commands/RegisterUserCommandHandler.php
2015-02-25 15:34:02 +10:30

36 lines
1.1 KiB
PHP

<?php namespace Flarum\Core\Handlers\Commands;
use Flarum\Core\Models\User;
use Flarum\Core\Events\UserWillBeSaved;
use Flarum\Core\Support\DispatchesEvents;
class RegisterUserCommandHandler
{
use DispatchesEvents;
public function handle($command)
{
// Assert the the current user has permission to create a user. In the
// case of a guest trying to register an account, this will depend on
// whether or not registration is open. If the user is an admin, though,
// it will be allowed.
$command->forum->assertCan($command->user, 'register');
// Create a new User entity, persist it, and dispatch domain events.
// Before persistance, though, fire an event to give plugins an
// opportunity to alter the post entity based on data in the command.
$user = User::register(
$command->username,
$command->email,
$command->password
);
event(new UserWillBeSaved($user, $command));
$user->save();
$this->dispatchEventsFor($user);
return $user;
}
}