Refactor validator stuff and fix variable names in views

This commit is contained in:
Graham Campbell
2015-08-03 22:32:36 +01:00
parent 5d958bac81
commit fcbbfdd84e
56 changed files with 514 additions and 766 deletions

View File

@@ -66,9 +66,7 @@ class ApiController extends AbstractController
$groupData = Binput::get('ids');
foreach ($groupData as $order => $groupId) {
ComponentGroup::find($groupId)->update([
'order' => $order + 1,
]);
ComponentGroup::find($groupId)->update(['order' => $order + 1]);
}
return $groupData;
@@ -85,12 +83,10 @@ class ApiController extends AbstractController
{
$templateSlug = Binput::get('slug');
$template = IncidentTemplate::where('slug', $templateSlug)->first();
if ($template) {
if ($template = IncidentTemplate::where('slug', $templateSlug)->first()) {
return $template;
}
throw new ModelNotFoundException('Incident template for '.$templateSlug.' could not be found.');
throw new ModelNotFoundException("Incident template for $templateSlug could not be found.");
}
}

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Http\Controllers\AbstractController;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
@@ -57,11 +58,10 @@ class ComponentController extends AbstractController
$this->subMenu['components']['active'] = true;
return View::make('dashboard.components.index')->with([
'page_title' => trans_choice('dashboard.components.components', 2).' - '.trans('dashboard.dashboard'),
'components' => $components,
'sub_menu' => $this->subMenu,
]);
return View::make('dashboard.components.index')
->withPageTitle(trans_choice('dashboard.components.components', 2).' - '.trans('dashboard.dashboard'))
->withComponents($components)
->withSubMenu($this->subMenu);
}
/**
@@ -73,11 +73,10 @@ class ComponentController extends AbstractController
{
$this->subMenu['groups']['active'] = true;
return View::make('dashboard.components.groups.index')->with([
'page_title' => trans_choice('dashboard.components.groups.groups', 2).' - '.trans('dashboard.dashboard'),
'groups' => ComponentGroup::orderBy('order')->get(),
'sub_menu' => $this->subMenu,
]);
return View::make('dashboard.components.groups.index')
->withPageTitle(trans_choice('dashboard.components.groups.groups', 2).' - '.trans('dashboard.dashboard'))
->withGroups(ComponentGroup::orderBy('order')->get())
->withSubMenu($this->subMenu);
}
/**
@@ -91,18 +90,12 @@ class ComponentController extends AbstractController
{
$groups = ComponentGroup::all();
$pageTitle = sprintf(
'"%s" - %s - %s',
$component->name,
trans('dashboard.components.edit.title'),
trans('dashboard.dashboard')
);
$pageTitle = sprintf('"%s" - %s - %s', $component->name, trans('dashboard.components.edit.title'), trans('dashboard.dashboard'));
return View::make('dashboard.components.edit')->with([
'page_title' => $pageTitle,
'component' => $component,
'groups' => $groups,
]);
return View::make('dashboard.components.edit')
->withPageTitle($pageTitle)
->withComponent($component)
->withGroups($groups);
}
/**
@@ -117,16 +110,13 @@ class ComponentController extends AbstractController
$_component = Binput::get('component');
$tags = array_pull($_component, 'tags');
$component->update($_component);
if (!$component->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.components.edit.failure')
))
->with('errors', $component->getErrors());
try {
$component->update($_component);
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.edit.failure')))
->withErrors($e->getMessageBag());
}
// The component was added successfully, so now let's deal with the tags.
@@ -134,20 +124,13 @@ class ComponentController extends AbstractController
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) use ($component) {
return Tag::firstOrCreate([
'name' => $taggable,
])->id;
return Tag::firstOrCreate(['name' => $taggable])->id;
}, $tags);
$component->tags()->sync($componentTags);
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.components.edit.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.edit.success')));
}
/**
@@ -157,12 +140,9 @@ class ComponentController extends AbstractController
*/
public function showAddComponent()
{
$groups = ComponentGroup::all();
return View::make('dashboard.components.add')->with([
'page_title' => trans('dashboard.components.add.title').' - '.trans('dashboard.dashboard'),
'groups' => $groups,
]);
return View::make('dashboard.components.add')
->withPageTitle(trans('dashboard.components.add.title').' - '.trans('dashboard.dashboard'))
->withGroups(ComponentGroup::all());
}
/**
@@ -176,16 +156,13 @@ class ComponentController extends AbstractController
// We deal with tags separately.
$tags = array_pull($_component, 'tags');
$component = Component::create($_component);
if (!$component->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.components.add.failure')
))
->with('errors', $component->getErrors());
try {
$component = Component::create($_component);
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.add.failure')))
->withErrors($e->getMessageBag());
}
// The component was added successfully, so now let's deal with the tags.
@@ -193,20 +170,13 @@ class ComponentController extends AbstractController
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) use ($component) {
return Tag::firstOrCreate([
'name' => $taggable,
])->id;
return Tag::firstOrCreate(['name' => $taggable])->id;
}, $tags);
$component->tags()->sync($componentTags);
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.components.add.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.add.success')));
}
/**
@@ -233,9 +203,7 @@ class ComponentController extends AbstractController
public function deleteComponentGroupAction(ComponentGroup $group)
{
$group->components->map(function ($component) {
$component->update([
'group_id' => 0,
]);
$component->update(['group_id' => 0]);
});
$group->delete();
@@ -250,9 +218,8 @@ class ComponentController extends AbstractController
*/
public function showAddComponentGroup()
{
return View::make('dashboard.components.groups.add')->with([
'page_title' => trans('dashboard.components.groups.add.title').' - '.trans('dashboard.dashboard'),
]);
return View::make('dashboard.components.groups.add')
->withPageTitle(trans('dashboard.components.groups.add.title').' - '.trans('dashboard.dashboard'));
}
/**
@@ -264,10 +231,9 @@ class ComponentController extends AbstractController
*/
public function showEditComponentGroup(ComponentGroup $group)
{
return View::make('dashboard.components.groups.edit')->with([
'page_title' => trans('dashboard.components.groups.edit.title').' - '.trans('dashboard.dashboard'),
'group' => $group,
]);
return View::make('dashboard.components.groups.edit')
->withPageTitle(trans('dashboard.components.groups.edit.title').' - '.trans('dashboard.dashboard'))
->withGroup($group);
}
/**
@@ -277,25 +243,17 @@ class ComponentController extends AbstractController
*/
public function postAddComponentGroup()
{
$group = ComponentGroup::create(Binput::get('group'));
if (!$group->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.components.groups.add.failure')
))
->with('errors', $group->getErrors());
try {
$group = ComponentGroup::create(Binput::get('group'));
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.add.failure')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.components.groups.add.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.add.success')));
}
/**
@@ -308,24 +266,17 @@ class ComponentController extends AbstractController
public function updateComponentGroupAction(ComponentGroup $group)
{
$groupData = Binput::get('group');
$group->update($groupData);
if (!$group->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.components.groups.edit.failure')
))
->with('errors', $group->getErrors());
try {
$group->update($groupData);
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.groups.edit.failure')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.components.groups.edit.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.groups.edit.success')));
}
}

View File

@@ -26,9 +26,8 @@ class DashboardController extends AbstractController
{
$components = Component::orderBy('order')->get();
return View::make('dashboard.index')->with([
'components' => $components,
]);
return View::make('dashboard.index')
->withComponents($components);
}
/**
@@ -38,8 +37,7 @@ class DashboardController extends AbstractController
*/
public function showNotifications()
{
return View::make('dashboard.notifications.index')->with([
'page_title' => trans('dashboard.notifications.notifications').' '.trans('dashboard.dashboard'),
]);
return View::make('dashboard.notifications.index')
->withPageTitle(trans('dashboard.notifications.notifications').' '.trans('dashboard.dashboard'));
}
}

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Events\IncidentHasReportedEvent;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Http\Controllers\AbstractController;
@@ -68,10 +69,9 @@ class IncidentController extends AbstractController
{
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
return View::make('dashboard.incidents.index')->with([
'page_title' => trans('dashboard.incidents.incidents').' - '.trans('dashboard.dashboard'),
'incidents' => $incidents,
]);
return View::make('dashboard.incidents.index')
->withPageTitle(trans('dashboard.incidents.incidents').' - '.trans('dashboard.dashboard'))
->withIncidents($incidents);
}
/**
@@ -81,15 +81,11 @@ class IncidentController extends AbstractController
*/
public function showAddIncident()
{
$componentsInGroups = ComponentGroup::with('components')->get();
$componentsOutGroups = Component::where('group_id', 0)->get();
return View::make('dashboard.incidents.add')->with([
'page_title' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
'componentsInGroups' => $componentsInGroups,
'componentsOutGroups' => $componentsOutGroups,
'incidentTemplates' => IncidentTemplate::all(),
]);
return View::make('dashboard.incidents.add')
->withPageTitle(trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'))
->withComponentsInGroups(ComponentGroup::with('components')->get())
->withComponentsOutGroups(Component::where('group_id', 0)->get())
->withIncidentTemplates(IncidentTemplate::all());
}
/**
@@ -99,10 +95,9 @@ class IncidentController extends AbstractController
*/
public function showTemplates()
{
return View::make('dashboard.incidents.templates.index')->with([
'page_title' => trans('dashboard.incidents.templates.title').' - '.trans('dashboard.dashboard'),
'incidentTemplates' => IncidentTemplate::all(),
]);
return View::make('dashboard.incidents.templates.index')
->withPageTitle(trans('dashboard.incidents.templates.title').' - '.trans('dashboard.dashboard'))
->withIncidentTemplates(IncidentTemplate::all());
}
/**
@@ -123,41 +118,26 @@ class IncidentController extends AbstractController
unset($incidentData['created_at']);
}
$incident = Incident::create($incidentData);
if (!$incident->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.incidents.add.failure')
))
->with('errors', $incident->getErrors());
try {
$incident = Incident::create($incidentData);
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))
->withErrors($e->getMessageBag());
}
// Update the component.
if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) {
Component::find($incidentData['component_id'])->update([
'status' => $componentStatus,
]);
Component::find($incidentData['component_id'])->update(['status' => $componentStatus]);
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.incidents.add.success')
);
$isEnabled = (bool) Setting::get('enable_subscribers', false);
$mailAddress = env('MAIL_ADDRESS', false);
$mailFrom = env('MAIL_NAME', false);
$subscribersEnabled = $isEnabled && $mailAddress && $mailFrom;
if (array_get($incidentData, 'notify') && $subscribersEnabled) {
if (array_get($incidentData, 'notify') && subscribers_enabled()) {
event(new IncidentHasReportedEvent($incident));
}
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success')));
}
/**
@@ -167,9 +147,8 @@ class IncidentController extends AbstractController
*/
public function showAddIncidentTemplate()
{
return View::make('dashboard.incidents.templates.add')->with([
'page_title' => trans('dashboard.incidents.templates.add.title').' - '.trans('dashboard.dashboard'),
]);
return View::make('dashboard.incidents.templates.add')
->withPageTitle(trans('dashboard.incidents.templates.add.title').' - '.trans('dashboard.dashboard'));
}
/**
@@ -181,10 +160,9 @@ class IncidentController extends AbstractController
*/
public function showEditTemplateAction(IncidentTemplate $template)
{
return View::make('dashboard.incidents.templates.edit')->with([
'page_title' => trans('dashboard.incidents.templates.edit.title').' - '.trans('dashboard.dashboard'),
'template' => $template,
]);
return View::make('dashboard.incidents.templates.edit')
->withPageTitle(trans('dashboard.incidents.templates.edit.title').' - '.trans('dashboard.dashboard'))
->withTemplate($template);
}
/**
@@ -208,26 +186,17 @@ class IncidentController extends AbstractController
*/
public function createIncidentTemplateAction()
{
$_template = Binput::get('template');
$template = IncidentTemplate::create($_template);
if (!$template->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.incidents.templates.add.failure')
))
->with('errors', $template->getErrors());
try {
IncidentTemplate::create(Binput::get('template'));
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.add.failure')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.incidents.templates.add.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.success')));
}
/**
@@ -253,15 +222,11 @@ class IncidentController extends AbstractController
*/
public function showEditIncidentAction(Incident $incident)
{
$componentsInGroups = ComponentGroup::with('components')->get();
$componentsOutGroups = Component::where('group_id', 0)->get();
return View::make('dashboard.incidents.edit')->with([
'page_title' => trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'),
'incident' => $incident,
'componentsInGroups' => $componentsInGroups,
'componentsOutGroups' => $componentsOutGroups,
]);
return View::make('dashboard.incidents.edit')
->withPageTitle(trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'))
->withIncident($incident)
->withComponentsInGroups(ComponentGroup::with('components')->get())
->withComponentsOutGroups(Component::where('group_id', 0)->get());
}
/**
@@ -283,32 +248,23 @@ class IncidentController extends AbstractController
unset($incidentData['created_at']);
}
$incident->update($incidentData);
if (!$incident->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.incidents.templates.edit.failure')
))
->with('errors', $incident->getErrors());
try {
$incident->update($incidentData);
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.edit.failure')))
->withErrors($e->getMessageBag());
}
$componentStatus = array_pull($incidentData, 'component_status');
if ($incident->component) {
$incident->component->update([
'status' => $componentStatus,
]);
$incident->component->update(['status' => $componentStatus]);
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.incidents.edit.success')
);
return Redirect::to('dashboard/incidents')->with('success', $successMsg);
return Redirect::to('dashboard/incidents')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success')));
}
/**
@@ -320,8 +276,15 @@ class IncidentController extends AbstractController
*/
public function editTemplateAction(IncidentTemplate $template)
{
$template->update(Binput::get('template'));
try {
$template->update(Binput::get('template'));
} catch (ValidationException $e) {
return Redirect::back()
->withUpdatedTemplate($template)
->withTemplateErrors($e->getMessageBag()->getErrors());
}
return Redirect::back()->with('updatedTemplate', $template);
return Redirect::back()
->withUpdatedTemplate($template);
}
}

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Http\Controllers\AbstractController;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\MetricPoint;
@@ -29,10 +30,9 @@ class MetricController extends AbstractController
{
$metrics = Metric::orderBy('created_at', 'desc')->get();
return View::make('dashboard.metrics.index')->with([
'page_title' => trans('dashboard.metrics.metrics').' - '.trans('dashboard.dashboard'),
'metrics' => $metrics,
]);
return View::make('dashboard.metrics.index')
->withPageTitle(trans('dashboard.metrics.metrics').' - '.trans('dashboard.dashboard'))
->withMetrics($metrics);
}
/**
@@ -42,10 +42,8 @@ class MetricController extends AbstractController
*/
public function showAddMetric()
{
return View::make('dashboard.metrics.add')->with([
'page_title' => trans('dashboard.metrics.add.title').' - '.trans('dashboard.dashboard'),
'metricMetricPoints' => MetricPoint::all(),
]);
return View::make('dashboard.metrics.add')
->withPageTitle(trans('dashboard.metrics.add.title').' - '.trans('dashboard.dashboard'));
}
/**
@@ -55,10 +53,9 @@ class MetricController extends AbstractController
*/
public function showMetricPoints()
{
return View::make('dashboard.metrics.points.index')->with([
'page_title' => trans('dashboard.metrics.points.title').' - '.trans('dashboard.dashboard'),
'metricMetricPoints' => MetricPoint::all(),
]);
return View::make('dashboard.metrics.points.index')
->withPageTitle(trans('dashboard.metrics.points.title').' - '.trans('dashboard.dashboard'))
->withMetrics(MetricPoint::all());
}
/**
@@ -68,26 +65,17 @@ class MetricController extends AbstractController
*/
public function createMetricAction()
{
$metricData = Binput::get('metric');
$metric = Metric::create($metricData);
if (!$metric->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.metrics.add.failure')
))
->with('errors', $metric->getErrors());
try {
Metric::create(Binput::get('metric'));
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.metrics.add.failure')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.metrics.add.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.add.success')));
}
/**
@@ -97,9 +85,8 @@ class MetricController extends AbstractController
*/
public function showAddMetricPoint()
{
return View::make('dashboard.metrics.points.add')->with([
'page_title' => trans('dashboard.metrics.points.add.title').' - '.trans('dashboard.dashboard'),
]);
return View::make('dashboard.metrics.points.add')
->withPageTitle(trans('dashboard.metrics.points.add.title').' - '.trans('dashboard.dashboard'));
}
/**
@@ -109,26 +96,17 @@ class MetricController extends AbstractController
*/
public function createMetricPointAction()
{
$_point = Binput::get('point', null, false);
$point = MetricPoint::create($_point);
if (!$point->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.metrics.points.add.failure')
))
->with('errors', $point->getErrors());
try {
MetricPoint::create(Binput::get('point', null, false));
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.metrics.points.add.failure')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.metrics.points.add.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.points.add.success')));
}
/**
@@ -154,10 +132,9 @@ class MetricController extends AbstractController
*/
public function showEditMetricAction(Metric $metric)
{
return View::make('dashboard.metrics.edit')->with([
'page_title' => trans('dashboard.metrics.edit.title').' - '.trans('dashboard.dashboard'),
'metric' => $metric,
]);
return View::make('dashboard.metrics.edit')
->withPageTitle(trans('dashboard.metrics.edit.title').' - '.trans('dashboard.dashboard'))
->withMetric($metric);
}
/**
@@ -169,24 +146,16 @@ class MetricController extends AbstractController
*/
public function editMetricAction(Metric $metric)
{
$metricData = Binput::get('metric', null, false);
$metric->update($metricData);
if (!$metric->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'<strong>%s</strong>',
trans('dashboard.notifications.whoops')
))
->with('errors', $metric->getErrors());
try {
$metric->update(Binput::get('metric', null, false));
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('<strong>%s</strong>', trans('dashboard.notifications.whoops')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.metrics.edit.success')
);
return Redirect::to('dashboard/metrics')->with('success', $successMsg);
return Redirect::to('dashboard/metrics')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.edit.success')));
}
}

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Events\MaintenanceHasScheduledEvent;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Http\Controllers\AbstractController;
@@ -80,9 +81,8 @@ class ScheduleController extends AbstractController
{
$incidentTemplates = IncidentTemplate::all();
return View::make('dashboard.schedule.add')->with([
'incidentTemplates' => $incidentTemplates,
]);
return View::make('dashboard.schedule.add')
->withIncidentTemplates($incidentTemplates);
}
/**
@@ -99,9 +99,7 @@ class ScheduleController extends AbstractController
if ($scheduledAt->isPast()) {
$messageBag = new MessageBag();
$messageBag->add('scheduled_at', trans('validation.date', [
'attribute' => 'scheduled time you supplied',
]));
$messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied']));
return Redirect::back()->withErrors($messageBag);
}
@@ -110,34 +108,21 @@ class ScheduleController extends AbstractController
// Bypass the incident.status field.
$scheduleData['status'] = 0;
$incident = Incident::create($scheduleData);
if (!$incident->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('success', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.schedule.add.failure')
))
->with('errors', $incident->getErrors());
try {
Incident::create($scheduleData);
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.add.failure')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.schedule.add.success')
);
$isEnabled = (bool) Setting::get('enable_subscribers', false);
$mailAddress = env('MAIL_ADDRESS', false);
$mailFrom = env('MAIL_NAME', false);
$subscribersEnabled = $isEnabled && $mailAddress && $mailFrom;
if (array_get($scheduleData, 'notify') && $subscribersEnabled) {
if (array_get($scheduleData, 'notify') && subscribers_enabled()) {
event(new MaintenanceHasScheduledEvent($incident));
}
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.add.success')));
}
/**
@@ -151,10 +136,9 @@ class ScheduleController extends AbstractController
{
$incidentTemplates = IncidentTemplate::all();
return View::make('dashboard.schedule.edit')->with([
'incidentTemplates' => $incidentTemplates,
'schedule' => $schedule,
]);
return View::make('dashboard.schedule.edit')
->withIncidentTemplates($incidentTemplates)
->withSchedule($schedule);
}
/**
@@ -173,9 +157,7 @@ class ScheduleController extends AbstractController
if ($scheduledAt->isPast()) {
$messageBag = new MessageBag();
$messageBag->add('scheduled_at', trans('validation.date', [
'attribute' => 'scheduled time you supplied',
]));
$messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied']));
return Redirect::back()->withErrors($messageBag);
}
@@ -184,25 +166,17 @@ class ScheduleController extends AbstractController
// Bypass the incident.status field.
$scheduleData['status'] = 0;
$schedule->update($scheduleData);
if (!$schedule->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.schedule.edit.failure')
))
->with('errors', $schedule->getErrors());
try {
$schedule->update($scheduleData);
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.schedule.edit.success')
);
return Redirect::to('dashboard/schedule')->with('success', $successMsg);
return Redirect::to('dashboard/schedule')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success')));
}
/**
@@ -216,10 +190,7 @@ class ScheduleController extends AbstractController
{
$schedule->delete();
return Redirect::back()->with('warning', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.schedule.delete.failure')
));
return Redirect::back()
->withWarning(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.delete.failure')));
}
}

View File

@@ -68,10 +68,9 @@ class SettingsController extends AbstractController
{
$this->subMenu['setup']['active'] = true;
return View::make('dashboard.settings.app-setup')->with([
'page_title' => 'Application Setup - Dashboard',
'sub_menu' => $this->subMenu,
]);
return View::make('dashboard.settings.app-setup')
->withPageTitle('Application Setup - Dashboard')
->withSubMenu($this->subMenu);
}
/**
@@ -83,10 +82,9 @@ class SettingsController extends AbstractController
{
$this->subMenu['theme']['active'] = true;
return View::make('dashboard.settings.theme')->with([
'page_title' => 'Theme - Dashboard',
'sub_menu' => $this->subMenu,
]);
return View::make('dashboard.settings.theme')
->withPageTitle('Theme - Dashboard')
->withSubMenu($this->subMenu);
}
/**
@@ -100,11 +98,10 @@ class SettingsController extends AbstractController
$unsecureUsers = User::whereNull('google_2fa_secret')->orWhere('google_2fa_secret', '')->get();
return View::make('dashboard.settings.security')->with([
'page_title' => 'Security - Dashboard',
'sub_menu' => $this->subMenu,
'unsecureUsers' => $unsecureUsers,
]);
return View::make('dashboard.settings.security')
->withPageTitle('Security - Dashboard')
->withSubMenu($this->subMenu)
->withUnsecureUsers($unsecureUsers);
}
/**
@@ -116,10 +113,9 @@ class SettingsController extends AbstractController
{
$this->subMenu['stylesheet']['active'] = true;
return View::make('dashboard.settings.stylesheet')->with([
'page_title' => 'Stylesheet - Dashboard',
'sub_menu' => $this->subMenu,
]);
return View::make('dashboard.settings.stylesheet')
->withPageTitle('Stylesheet - Dashboard')
->withSubMenu($this->subMenu);
}
/**
@@ -142,9 +138,7 @@ class SettingsController extends AbstractController
$maxSize = $file->getMaxFilesize();
if ($file->getSize() > $maxSize) {
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.too-big', [
'size' => $maxSize,
]));
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.too-big', ['size' => $maxSize]));
}
if (!$file->isValid() || $file->getError()) {
@@ -156,18 +150,10 @@ class SettingsController extends AbstractController
}
// Store the banner.
Setting::firstOrCreate([
'name' => 'app_banner',
])->update([
'value' => base64_encode(file_get_contents($file->getRealPath())),
]);
Setting::firstOrCreate(['name' => 'app_banner'])->update(['value' => base64_encode(file_get_contents($file->getRealPath()))]);
// Store the banner type
Setting::firstOrCreate([
'name' => 'app_banner_type',
])->update([
'value' => $file->getMimeType(),
]);
Setting::firstOrCreate(['name' => 'app_banner_type'])->update(['value' => $file->getMimeType()]);
}
try {
@@ -176,18 +162,15 @@ class SettingsController extends AbstractController
$settingValue = rtrim($settingValue, '/');
}
Setting::firstOrCreate([
'name' => $settingName,
])->update([
'value' => $settingValue,
]);
Setting::firstOrCreate(['name' => $settingName])->update(['value' => $settingValue]);
}
} catch (Exception $e) {
return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure'));
return Redirect::back()->withErrors(trans('dashboard.settings.edit.failure'));
}
Lang::setLocale(Binput::get('app_locale'));
return Redirect::back()->with('success', trans('dashboard.settings.edit.success'));
return Redirect::back()
->withSuccess(trans('dashboard.settings.edit.success'));
}
}

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Events\CustomerHasSubscribedEvent;
use CachetHQ\Cachet\Http\Controllers\AbstractController;
use CachetHQ\Cachet\Models\Subscriber;
@@ -30,10 +31,8 @@ class SubscriberController extends AbstractController
$subscribers = Subscriber::all();
return View::make('dashboard.subscribers.index')
->with([
'page_title' => trans('dashboard.subscribers.subscribers').' - '.trans('dashboard.dashboard'),
'subscribers' => $subscribers,
]);
->withPageTitle(trans('dashboard.subscribers.subscribers').' - '.trans('dashboard.dashboard'))
->withSubscribers(Subscriber::all());
}
/**
@@ -44,10 +43,7 @@ class SubscriberController extends AbstractController
public function showAddSubscriber()
{
return View::make('dashboard.subscribers.add')
->with([
'page_title' => trans('dashboard.subscribers.add.title').' - '.trans('dashboard.dashboard'),
'incidentTemplates' => Subscriber::all(),
]);
->withPageTitle(trans('dashboard.subscribers.add.title').' - '.trans('dashboard.dashboard'));
}
/**
@@ -59,31 +55,19 @@ class SubscriberController extends AbstractController
{
$email = Binput::get('email');
$subscriber = Subscriber::create([
'email' => $email,
]);
if (!$subscriber->isValid()) {
try {
$subscriber = Subscriber::create(['email' => $email]);
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.subscribers.add.failure')
))
->with('errors', $subscriber->getErrors());
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.subscribers.add.failure')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.subscribers.add.success')
);
event(new CustomerHasSubscribedEvent($subscriber));
return Redirect::back()
->with('success', $successMsg);
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.subscribers.add.success')));
}
/**

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Http\Controllers\AbstractController;
use CachetHQ\Cachet\Models\User;
use GrahamCampbell\Binput\Facades\Binput;
@@ -28,10 +29,9 @@ class TeamController extends AbstractController
{
$team = User::all();
return View::make('dashboard.team.index')->with([
'page_title' => trans('dashboard.team.team').' - '.trans('dashboard.dashboard'),
'teamMembers' => $team,
]);
return View::make('dashboard.team.index')
->withPageTitle(trans('dashboard.team.team').' - '.trans('dashboard.dashboard'))
->withTeamMembers($team);
}
/**
@@ -41,10 +41,9 @@ class TeamController extends AbstractController
*/
public function showTeamMemberView(User $user)
{
return View::make('dashboard.team.edit')->with([
'page_title' => trans('dashboard.team.edit.title').' - '.trans('dashboard.dashboard'),
'user' => $user,
]);
return View::make('dashboard.team.edit')
->withPageTitle(trans('dashboard.team.edit.title').' - '.trans('dashboard.dashboard'))
->withUser($user);
}
/**
@@ -54,9 +53,8 @@ class TeamController extends AbstractController
*/
public function showAddTeamMemberView()
{
return View::make('dashboard.team.add')->with([
'page_title' => trans('dashboard.team.add.title').' - '.trans('dashboard.dashboard'),
]);
return View::make('dashboard.team.add')
->withPageTitle(trans('dashboard.team.add.title').' - '.trans('dashboard.dashboard'));
}
/**
@@ -66,25 +64,17 @@ class TeamController extends AbstractController
*/
public function postAddUser()
{
$user = User::create(Binput::all());
if (!$user->isValid()) {
return Redirect::back()->withInput(Binput::except('password'))
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.team.add.failure')
))
->with('errors', $user->getErrors());
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());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.team.add.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.add.success')));
}
/**
@@ -104,24 +94,16 @@ class TeamController extends AbstractController
unset($items['password']);
}
$user->update($items);
if (!$user->isValid()) {
return Redirect::back()->withInput(Binput::except('password'))
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.team.edit.failure')
))
->with('errors', $user->getErrors());
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());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.team.edit.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')));
}
}

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Http\Controllers\AbstractController;
use CachetHQ\Cachet\Models\User;
use GrahamCampbell\Binput\Facades\Binput;
@@ -28,9 +29,8 @@ class UserController extends AbstractController
*/
public function showUser()
{
return View::make('dashboard.user.index')->with([
'page_title' => trans('dashboard.team.profile').' - '.trans('dashboard.dashboard'),
]);
return View::make('dashboard.user.index')
->withPageTitle(trans('dashboard.team.profile').' - '.trans('dashboard.dashboard'));
}
/**
@@ -56,26 +56,17 @@ class UserController extends AbstractController
unset($items['password']);
}
$user = Auth::user();
$user->update($items);
if (!$user->isValid()) {
return Redirect::back()->withInput(Binput::except('password'))
->with('title', sprintf(
'%s %s',
trans('dashboard.notifications.whoops'),
trans('dashboard.team.edit.failure')
))
->with('errors', $user->getErrors());
try {
Auth::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());
}
$successMsg = sprintf(
'%s %s',
trans('dashboard.notifications.awesome'),
trans('dashboard.team.edit.success')
);
return Redirect::back()->with('success', $successMsg);
return Redirect::back()
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')));
}
/**

View File

@@ -64,10 +64,6 @@ class ComponentController extends AbstractApiController
throw new BadRequestHttpException();
}
if (!$component->isValid()) {
throw new BadRequestHttpException();
}
if (Binput::has('tags')) {
// The component was added successfully, so now let's deal with the tags.
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
@@ -94,9 +90,9 @@ class ComponentController extends AbstractApiController
*/
public function putComponent(Component $component)
{
$component->update(Binput::except('tags'));
if (!$component->isValid('updating')) {
try {
$component->update(Binput::except('tags'));
} catch (Exception $e) {
throw new BadRequestHttpException();
}
@@ -105,9 +101,7 @@ class ComponentController extends AbstractApiController
// For every tag, do we need to create it?
$componentTags = array_map(function ($taggable) use ($component) {
return Tag::firstOrCreate([
'name' => $taggable,
])->id;
return Tag::firstOrCreate(['name' => $taggable])->id;
}, $tags);
$component->tags()->sync($componentTags);

View File

@@ -12,7 +12,6 @@
namespace CachetHQ\Cachet\Http\Controllers\Api;
use CachetHQ\Cachet\Events\IncidentHasReportedEvent;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Incident;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
@@ -34,8 +33,7 @@ class IncidentController extends AbstractApiController
{
$incidentVisiblity = $auth->check() ? 0 : 1;
$incidents = Incident::where('visible', '>=', $incidentVisiblity)
->paginate(Binput::get('per_page', 20));
$incidents = Incident::where('visible', '>=', $incidentVisiblity)->paginate(Binput::get('per_page', 20));
return $this->paginator($incidents, $request);
}
@@ -73,20 +71,11 @@ class IncidentController extends AbstractApiController
throw new BadRequestHttpException();
}
$isEnabled = (bool) Setting::get('enable_subscribers', false);
$mailAddress = env('MAIL_ADDRESS', false);
$mailFrom = env('MAIL_NAME', false);
$subscribersEnabled = $isEnabled && $mailAddress && $mailFrom;
if (array_get($incidentData, 'notify') && $subscribersEnabled) {
if (array_get($incidentData, 'notify') && subscribers_enabled()) {
event(new IncidentHasReportedEvent($incident));
}
if ($incident->isValid()) {
return $this->item($incident);
}
throw new BadRequestHttpException();
return $this->item($incident);
}
/**
@@ -98,13 +87,13 @@ class IncidentController extends AbstractApiController
*/
public function putIncident(Incident $incident)
{
$incident->update(Binput::all());
if ($incident->isValid('updating')) {
return $this->item($incident);
try {
$incident->update(Binput::all());
} catch (Exception $e) {
throw new BadRequestHttpException();
}
throw new BadRequestHttpException();
return $this->item($incident);
}
/**

View File

@@ -70,11 +70,7 @@ class MetricController extends AbstractApiController
throw new BadRequestHttpException();
}
if ($metric->isValid()) {
return $this->item($metric);
}
throw new BadRequestHttpException();
return $this->item($metric);
}
/**
@@ -86,13 +82,13 @@ class MetricController extends AbstractApiController
*/
public function putMetric(Metric $metric)
{
$metric->update(Binput::all());
if ($metric->isValid('updating')) {
return $this->item($metric);
try {
$metric->update(Binput::all());
} catch (Exception $e) {
throw new BadRequestHttpException();
}
throw new BadRequestHttpException();
return $this->item($metric);
}
/**

View File

@@ -49,16 +49,12 @@ class SubscriberController extends AbstractApiController
throw new BadRequestHttpException();
}
if ($subscriber->isValid()) {
// If we're auto-verifying the subscriber, don't bother with this event.
if (!(Binput::get('verify'))) {
event(new CustomerHasSubscribedEvent($subscriber));
}
return $this->item($subscriber);
// If we're auto-verifying the subscriber, don't bother with this event.
if (!(Binput::get('verify'))) {
event(new CustomerHasSubscribedEvent($subscriber));
}
throw new BadRequestHttpException();
return $this->item($subscriber);
}
/**

View File

@@ -56,6 +56,8 @@ class AtomController extends AbstractController
*
* @param \Roumen\Feed\Facades\Feed $feed
* @param \CachetHQ\Cachet\Models\Incident $incident
*
* @return void
*/
private function feedAddItem(&$feed, $incident)
{

View File

@@ -19,9 +19,6 @@ use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\View;
use PragmaRX\Google2FA\Vendor\Laravel\Facade as Google2FA;
/**
* Logs users into their account.
*/
class AuthController extends AbstractController
{
/**
@@ -31,9 +28,8 @@ class AuthController extends AbstractController
*/
public function showLogin()
{
return View::make('auth.login')->with([
'page_title' => trans('dashboard.login.login'),
]);
return View::make('auth.login')
->withPageTitle(trans('dashboard.login.login'));
}
/**
@@ -64,7 +60,7 @@ class AuthController extends AbstractController
return Redirect::back()
->withInput(Binput::except('password'))
->with('error', trans('forms.login.invalid'));
->withError(trans('forms.login.invalid'));
}
/**
@@ -101,11 +97,11 @@ class AuthController extends AbstractController
// Failed login, log back out.
Auth::logout();
return Redirect::route('login')->with('error', trans('forms.login.invalid-token'));
return Redirect::route('login')->withError(trans('forms.login.invalid-token'));
}
}
return Redirect::route('login')->with('error', trans('forms.login.invalid-token'));
return Redirect::route('login')->withError(trans('forms.login.invalid-token'));
}
/**

View File

@@ -92,21 +92,18 @@ class HomeController extends AbstractController
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
$canPageBackward = Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() != 0;
return View::make('index', [
'componentGroups' => $componentGroups,
'ungroupedComponents' => $ungroupedComponents,
'displayMetrics' => $displayMetrics,
'metrics' => $metrics,
'allIncidents' => $allIncidents,
'scheduledMaintenance' => $scheduledMaintenance,
'aboutApp' => Markdown::convertToHtml(Setting::get('app_about')),
'canPageForward' => (bool) $today->gt($startDate),
'canPageBackward' => $canPageBackward,
'previousDate' => $startDate->copy()->subDays($daysToShow)->toDateString(),
'nextDate' => $startDate->copy()->addDays($daysToShow)->toDateString(),
'page_title' => Setting::get('app_name'),
]);
return View::make('index')
->withComponentGroups($componentGroups)
->withUngroupedComponents($ungroupedComponents)
->withDisplayMetrics($displayMetrics)
->withMetrics($metrics)
->withAllIncidents($allIncidents)
->withScheduledMaintenance($scheduledMaintenance)
->withAboutApp(Markdown::convertToHtml(Setting::get('app_about')))
->withCanPageForward((bool) $today->gt($startDate))
->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0)
->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString())
->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString())
->withPageTitle(Setting::get('app_name'));
}
}

View File

@@ -41,6 +41,8 @@ class SetupController extends AbstractController
/**
* Create a new setup controller instance.
*
* @return void
*/
public function __construct()
{
@@ -59,11 +61,10 @@ class SetupController extends AbstractController
$this->keyGenerate();
}
return View::make('setup')->with([
'page_title' => trans('setup.setup'),
'cacheDrivers' => $this->cacheDrivers,
'appUrl' => Request::root(),
]);
return View::make('setup')
->withPageTitle(trans('setup.setup'))
->withCacheDrivers($this->cacheDrivers)
->withAppUrl(Request::root());
}
/**
@@ -82,9 +83,9 @@ class SetupController extends AbstractController
if ($v->passes()) {
return Response::json(['status' => 1]);
} else {
return Response::json(['errors' => $v->messages()], 400);
}
return Response::json(['errors' => $v->getMessageBag()], 400);
}
/**
@@ -108,9 +109,9 @@ class SetupController extends AbstractController
if ($v->passes()) {
return Response::json(['status' => 1]);
} else {
return Response::json(['errors' => $v->messages()], 400);
}
return Response::json(['errors' => $v->getMessageBag()], 400);
}
/**
@@ -171,13 +172,13 @@ class SetupController extends AbstractController
}
return Redirect::to('dashboard');
} else {
if (Request::ajax()) {
return Response::json(['errors' => $v->messages()], 400);
}
return Redirect::back()->withInput()->with('errors', $v->messages());
}
if (Request::ajax()) {
return Response::json(['errors' => $v->getMessageBag()], 400);
}
return Redirect::back()->withInput()->withErrors($v->getMessageBag());
}
/**
@@ -185,6 +186,8 @@ class SetupController extends AbstractController
*
* @param string $key
* @param mixed $value
*
* @return void
*/
protected function writeEnv($key, $value)
{
@@ -200,6 +203,8 @@ class SetupController extends AbstractController
/**
* Generate the app.key value.
*
* @return void
*/
protected function keyGenerate()
{

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Events\CustomerHasSubscribedEvent;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Subscriber;
@@ -30,10 +31,9 @@ class SubscribeController extends AbstractController
*/
public function showSubscribe()
{
return View::make('subscribe', [
'page_title' => Setting::get('app_name'),
'aboutApp' => Markdown::convertToHtml(Setting::get('app_about')),
]);
return View::make('subscribe')
->withPageTitle(Setting::get('app_name'))
->withAboutApp(Markdown::convertToHtml(Setting::get('app_about')));
}
/**
@@ -43,33 +43,25 @@ class SubscribeController extends AbstractController
*/
public function postSubscribe()
{
$subscriber = Subscriber::create(['email' => Binput::get('email')]);
if (!$subscriber->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf(
'<strong>%s</strong> %s',
trans('dashboard.notifications.whoops'),
trans('cachet.subscriber.email.failure')
))
->with('errors', $subscriber->getErrors());
try {
$subscriber = Subscriber::create(['email' => Binput::get('email')]);
} catch (ValidationException $e) {
return Redirect::back()
->withInput(Binput::all())
->withTitle(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.whoops'), trans('cachet.subscriber.email.failure')))
->withErrors($e->getMessageBag());
}
$successMsg = sprintf(
'<strong>%s</strong> %s',
trans('dashboard.notifications.awesome'),
trans('cachet.subscriber.email.subscribed')
);
event(new CustomerHasSubscribedEvent($subscriber));
return Redirect::route('status-page')->with('success', $successMsg);
return Redirect::route('status-page')
->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.subscribed')));
}
/**
* Handle the verify subscriber email.
*
* @param string $code
* @param string|null $code
*
* @return \Illuminate\View\View
*/
@@ -88,19 +80,14 @@ class SubscribeController extends AbstractController
$subscriber->verified_at = Carbon::now();
$subscriber->save();
$successMsg = sprintf(
'<strong>%s</strong> %s',
trans('dashboard.notifications.awesome'),
trans('cachet.subscriber.email.verified')
);
return Redirect::route('status-page')->with('success', $successMsg);
return Redirect::route('status-page')
->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.verified')));
}
/**
* Handle the unsubscribe.
*
* @param string $code
* @param string|null $code
*
* @return \Illuminate\View\View
*/
@@ -118,12 +105,7 @@ class SubscribeController extends AbstractController
$subscriber->delete();
$successMsg = sprintf(
'<strong>%s</strong> %s',
trans('dashboard.notifications.awesome'),
trans('cachet.subscriber.email.unsuscribed')
);
return Redirect::route('status-page')->with('success', $successMsg);
return Redirect::route('status-page')
->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.subscriber.email.unsuscribed')));
}
}