Change validation to controllers and partial

This commit is contained in:
Joseph Cohen
2015-01-09 20:21:29 -06:00
parent 996aceadcf
commit f47fb9823e
22 changed files with 117 additions and 208 deletions

View File

@@ -99,7 +99,13 @@ class DashComponentController extends Controller
$_component = Binput::get('component');
$component->update($_component);
return Redirect::back()->with('savedComponent', $component);
if (! $component->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.whoops'), trans('dashboard.components.edit.failure')))
->with('errors', $component->getErrors());
}
return Redirect::back()->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.components.edit.success')));
}
/**
@@ -127,7 +133,13 @@ class DashComponentController extends Controller
$_component = Binput::get('component');
$component = Component::create($_component);
return Redirect::back()->with('component', $component);
if (! $component->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.whoops'), trans('dashboard.components.add.failure')))
->with('errors', $component->getErrors());
}
return Redirect::back()->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.components.add.success')));
}
/**
@@ -179,6 +191,12 @@ class DashComponentController extends Controller
{
$group = ComponentGroup::create(Binput::get('group'));
return Redirect::back()->withGroup($group);
if (! $group->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.add.failure')))
->with('errors', $group->getErrors());
}
return Redirect::back()->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.add.success')));
}
}

View File

@@ -38,6 +38,24 @@ class DashIncidentController extends Controller
]);
}
/**
* Creates a new incident.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createIncidentAction()
{
$incident = Incident::create(Binput::get('incident'));
if (! $incident->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))
->with('errors', $incident->getErrors());
}
return Redirect::back()->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success')));
}
/**
* Shows the add incident template view.
*
@@ -60,19 +78,13 @@ class DashIncidentController extends Controller
$_template = Binput::get('template');
$template = IncidentTemplate::create($_template);
return Redirect::back()->with('template', $template);
}
if (! $template->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.failure')))
->with('errors', $template->getErrors());
}
/**
* Creates a new incident.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createIncidentAction()
{
$incident = Incident::create(Binput::get('incident'));
return Redirect::back()->withInput(Binput::all())->with('incident', $incident);
return Redirect::back()->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.success')));
}
/**
@@ -116,6 +128,12 @@ class DashIncidentController extends Controller
$_incident = Binput::get('incident');
$incident->update($_incident);
return Redirect::to('dashboard/incidents');
if (! $incident->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.edit.failure')))
->with('errors', $incident->getErrors());
}
return Redirect::to('dashboard/incidents')->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success')));
}
}

View File

@@ -46,6 +46,7 @@ class DashSettingsController extends Controller
];
View::share('subTitle', $this->subTitle);
View::share('subMenu', $this->subMenu);
}
@@ -167,15 +168,15 @@ class DashSettingsController extends Controller
$maxSize = $file->getMaxFilesize();
if ($file->getSize() > $maxSize) {
return Redirect::back()->withErrorMessage("You need to upload an image that is less than $maxSize.");
return Redirect::back()->withErrors("You need to upload an image that is less than $maxSize.");
}
if (!$file->isValid() || $file->getError()) {
return Redirect::back()->withErrorMessage($file->getErrorMessage());
return Redirect::back()->withErrors($file->getErrorMessage());
}
if (strpos($file->getMimeType(), 'image/') !== 0) {
return Redirect::back()->withErrorMessage('Only images may be uploaded.');
return Redirect::back()->withErrors('Only images may be uploaded.');
}
// Store the banner.
@@ -202,9 +203,9 @@ class DashSettingsController extends Controller
]);
}
} catch (Exception $e) {
return Redirect::back()->withSaved(false);
return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure'));
}
return Redirect::back()->withSaved(true);
return Redirect::back()->with('success', trans('dashboard.settings.edit.success'));
}
}

View File

@@ -47,9 +47,16 @@ class DashUserController extends Controller
unset($items['password']);
}
$updated = Auth::user()->update($items);
$user = Auth::user();
$user->update($items);
return Redirect::back()->with('updated', $updated);
if (! $user->isValid()) {
return Redirect::back()->withInput(Binput::except('password'))
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))
->with('errors', $user->getErrors());
}
return Redirect::back()->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')));
}
/**

View File

@@ -3,10 +3,7 @@
namespace CachetHQ\Cachet\Http\Controllers;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\User;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
class DashboardController extends Controller
@@ -26,80 +23,6 @@ class DashboardController extends Controller
]);
}
/**
* Shows the team members view.
*
* @return \Illuminate\View\View
*/
public function showTeamView()
{
$team = User::all();
return View::make('dashboard.team.index')->with([
'pageTitle' => trans('dashboard.team.team').' - '.trans('dashboard.dashboard'),
'teamMembers' => $team,
]);
}
/**
* Shows the edit team member view.
*
* @return \Illuminate\View\View
*/
public function showTeamMemberView(User $user)
{
return View::make('dashboard.team.edit')->with([
'pageTitle' => trans('dashboard.team.edit.title').' - '.trans('dashboard.dashboard'),
'user' => $user,
]);
}
/**
* Shows the add team member view.
*
* @return \Illuminate\View\View
*/
public function showAddTeamMemberView()
{
return View::make('dashboard.team.add')->with([
'pageTitle' => trans('dashboard.team.add.title').' - '.trans('dashboard.dashboard'),
]);
}
/**
* Creates a new team member.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function postAddUser()
{
$user = User::create(Binput::all());
if ($user->isValid()) {
return Redirect::back()->with('created', $user->isValid());
} else {
return Redirect::back()
->withInput(Binput::except('password'))
->with('errors', $user->getErrors());
}
}
/**
* Updates a user.
*
* @param \CachetHQ\Cachet\Models\User $user
*
* @return \Illuminate\View\View
*/
public function postUpdateUser(User $user)
{
$items = Binput::all();
$updated = $user->update($items);
return Redirect::back()->with('updated', $updated);
}
/**
* Shows the metrics view.
*