Added AddTeamMemberCommand

This commit is contained in:
James Brooks
2015-08-31 09:04:35 +01:00
parent 25a3626de5
commit 37d7908606
3 changed files with 79 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Events\User;
use CachetHQ\Cachet\Models\User;
class UserWasAddedEvent
{
/**
* The user that has been added.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new user was added event instance.
*/
public function __construct(User $user)
{
$this->user = $user;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Handlers\Commands\User;
use CachetHQ\Cachet\Commands\User\AddTeamMemberCommand;
use CachetHQ\Cachet\Events\User\UserWasAddedEvent;
use CachetHQ\Cachet\Models\User;
class AddTeamMemberCommandHandler
{
/**
* Handle the add team member command.
*
* @param \CachetHQ\Cachet\Commands\User\AddTeamMemberCommand $command
*
* @return void
*/
public function handle(AddTeamMemberCommand $command)
{
$user = User::create([
'username' => $command->username,
'password' => $command->password,
'email' => $command->email,
'level' => $command->level,
]);
event(new UserWasAddedEvent($user));
return $user;
}
}

View File

@@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Commands\User\AddTeamMemberCommand;
use CachetHQ\Cachet\Commands\User\RemoveUserCommand;
use CachetHQ\Cachet\Models\User;
use GrahamCampbell\Binput\Facades\Binput;
@@ -69,7 +70,12 @@ class TeamController extends Controller
public function postAddUser()
{
try {
User::create(Binput::all());
$this->dispatch(new AddTeamMemberCommand(
Binput::get('username'),
Binput::get('password'),
Binput::get('email'),
Binput::get('level')
));
} catch (ValidationException $e) {
return Redirect::route('dashboard.team.add')
->withInput(Binput::except('password'))