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-03-20 18:30:45 -06:00
|
|
|
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
2015-01-09 20:20:12 -06:00
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
use AltThree\Validator\ValidationException;
|
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\Redirect;
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new team member.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function postAddUser()
|
|
|
|
{
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
|
|
|
User::create(Binput::all());
|
|
|
|
} catch (ValidationException $e) {
|
|
|
|
return Redirect::back()
|
|
|
|
->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
|
|
|
}
|
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
return Redirect::back()
|
|
|
|
->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)
|
|
|
|
{
|
|
|
|
$items = Binput::all();
|
|
|
|
|
|
|
|
$passwordChange = array_get($items, 'password');
|
|
|
|
|
|
|
|
if (trim($passwordChange) === '') {
|
|
|
|
unset($items['password']);
|
|
|
|
}
|
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
try {
|
|
|
|
$user->update($items);
|
|
|
|
} catch (ValidationException $e) {
|
|
|
|
return Redirect::back()
|
|
|
|
->withInput(Binput::except('password'))
|
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))
|
|
|
|
->withErrors($e->getMessageBag());
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|
|
|
|
|
2015-08-03 22:32:36 +01:00
|
|
|
return Redirect::back()
|
|
|
|
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')));
|
2015-01-09 20:20:12 -06:00
|
|
|
}
|
|
|
|
}
|