1
0
mirror of https://github.com/flarum/core.git synced 2025-07-25 02:31:17 +02:00
Files
php-flarum/src/Core/Handlers/Commands/RegisterUserCommandHandler.php
Toby Zerner 8f29679b46 Convert the rest of the API to new action architecture
Also make some tweaks:
- Merge SerializeAction::$include and
SerializeAction::$includeAvailable into a keyed boolean array
- Set defaults for SerializeAction::$limit and $limitMax
- Rename SerializeAction::$sortAvailable to $sortFields
2015-05-03 12:04:43 +09: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(
array_get($command->data, 'username'),
array_get($command->data, 'email'),
array_get($command->data, 'password')
);
event(new UserWillBeSaved($user, $command));
$user->save();
$this->dispatchEventsFor($user);
return $user;
}
}