2015-01-09 20:20:12 -06:00
|
|
|
<?php
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-07-06 17:37:01 +01:00
|
|
|
* (c) Alt Three Services Limited
|
2015-04-19 08:52:39 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-08-31 18:59:17 +01:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
|
2015-01-09 20:20:12 -06:00
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
use AltThree\Validator\ValidationException;
|
2016-07-21 11:45:40 +01:00
|
|
|
use CachetHQ\Cachet\Bus\Commands\User\AddUserCommand;
|
|
|
|
use CachetHQ\Cachet\Bus\Commands\User\InviteUserCommand;
|
2016-01-05 02:38:07 +00:00
|
|
|
use CachetHQ\Cachet\Bus\Commands\User\RemoveUserCommand;
|
2015-01-09 20:20:12 -06:00
|
|
|
use CachetHQ\Cachet\Models\User;
|
|
|
|
use GrahamCampbell\Binput\Facades\Binput;
|
2015-08-05 17:18:51 -05:00
|
|
|
use Illuminate\Routing\Controller;
|
2015-01-09 20:20:12 -06:00
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
|
2015-08-05 17:18:51 -05:00
|
|
|
class TeamController extends Controller
|
2015-01-09 20:20:12 -06:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Shows the team members view.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showTeamView()
|
|
|
|
{
|
|
|
|
$team = User::all();
|
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
return View::make('dashboard.team.index')
|
|
|
|
->withPageTitle(trans('dashboard.team.team').' - '.trans('dashboard.dashboard'))
|
|
|
|
->withTeamMembers($team);
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the edit team member view.
|
|
|
|
*
|
2015-12-22 12:14:47 +00:00
|
|
|
* @param \CachetHQ\Cachet\Models\User $user
|
2015-12-22 08:41:03 +00:00
|
|
|
*
|
2015-01-09 20:20:12 -06:00
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showTeamMemberView(User $user)
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
return View::make('dashboard.team.edit')
|
|
|
|
->withPageTitle(trans('dashboard.team.edit.title').' - '.trans('dashboard.dashboard'))
|
|
|
|
->withUser($user);
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the add team member view.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showAddTeamMemberView()
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
return View::make('dashboard.team.add')
|
|
|
|
->withPageTitle(trans('dashboard.team.add.title').' - '.trans('dashboard.dashboard'));
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|
|
|
|
|
2015-10-31 15:33:11 -06:00
|
|
|
/**
|
|
|
|
* Shows the invite team member view.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function showInviteTeamMemberView()
|
|
|
|
{
|
|
|
|
return View::make('dashboard.team.invite')
|
|
|
|
->withPageTitle(trans('dashboard.team.invite.title').' - '.trans('dashboard.dashboard'));
|
|
|
|
}
|
|
|
|
|
2015-01-09 20:20:12 -06:00
|
|
|
/**
|
|
|
|
* Creates a new team member.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function postAddUser()
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
2016-07-21 11:45:40 +01:00
|
|
|
dispatch(new AddUserCommand(
|
2015-08-31 09:04:35 +01:00
|
|
|
Binput::get('username'),
|
|
|
|
Binput::get('password'),
|
|
|
|
Binput::get('email'),
|
|
|
|
Binput::get('level')
|
|
|
|
));
|
2015-08-03 22:32:36 +01:00
|
|
|
} catch (ValidationException $e) {
|
2016-10-13 09:51:44 +02:00
|
|
|
return cachet_redirect('dashboard.team.create')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withInput(Binput::except('password'))
|
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.add.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|
|
|
|
|
2016-10-13 09:51:44 +02:00
|
|
|
return cachet_redirect('dashboard.team.create')
|
2015-08-03 22:32:36 +01:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.add.success')));
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates a user.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\User $user
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function postUpdateUser(User $user)
|
|
|
|
{
|
2015-11-07 17:09:09 +00:00
|
|
|
$userData = array_filter(Binput::only(['username', 'email', 'password', 'level']));
|
2015-01-09 20:20:12 -06:00
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
2015-08-31 19:32:06 +01:00
|
|
|
$user->update($userData);
|
2015-08-03 22:32:36 +01:00
|
|
|
} catch (ValidationException $e) {
|
2016-10-13 09:51:44 +02:00
|
|
|
return cachet_redirect('dashboard.team.edit', [$user->id])
|
2015-08-31 19:32:06 +01:00
|
|
|
->withInput($userData)
|
2015-08-03 22:32:36 +01:00
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|
|
|
|
|
2016-10-13 09:51:44 +02:00
|
|
|
return cachet_redirect('dashboard.team.edit', [$user->id])
|
2015-08-03 22:32:36 +01:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')));
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|
2015-08-06 13:48:23 +01:00
|
|
|
|
2015-10-31 15:33:11 -06:00
|
|
|
/**
|
|
|
|
* Creates a new team member.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function postInviteUser()
|
|
|
|
{
|
|
|
|
try {
|
2016-07-21 11:45:40 +01:00
|
|
|
dispatch(new InviteUserCommand(
|
2015-10-31 15:33:11 -06:00
|
|
|
array_unique(array_filter((array) Binput::get('emails')))
|
|
|
|
));
|
|
|
|
} catch (ValidationException $e) {
|
2016-10-13 09:51:44 +02:00
|
|
|
return cachet_redirect('dashboard.team.invite')
|
2015-10-31 15:33:11 -06:00
|
|
|
->withInput(Binput::except('password'))
|
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.invite.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
|
|
|
}
|
|
|
|
|
2016-10-13 09:51:44 +02:00
|
|
|
return cachet_redirect('dashboard.team.invite')
|
2015-10-31 15:33:11 -06:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.invite.success')));
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:48:23 +01:00
|
|
|
/**
|
|
|
|
* Delete a user.
|
|
|
|
*
|
|
|
|
* @param \CachetHQ\Cachet\Models\User $user
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function deleteUser(User $user)
|
|
|
|
{
|
2015-12-24 15:16:09 +00:00
|
|
|
dispatch(new RemoveUserCommand($user));
|
2015-08-06 13:48:23 +01:00
|
|
|
|
2016-10-13 09:51:44 +02:00
|
|
|
return cachet_redirect('dashboard.team')
|
2015-08-06 13:48:23 +01:00
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.delete.success')));
|
|
|
|
}
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|