Cachet is now a Laravel 5 app
This commit is contained in:
12
app/Http/Controllers/AbstractController.php
Normal file
12
app/Http/Controllers/AbstractController.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesCommands;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
abstract class AbstractController extends BaseController
|
||||
{
|
||||
use DispatchesCommands, ValidatesRequests;
|
||||
}
|
||||
69
app/Http/Controllers/Admin/ApiController.php
Normal file
69
app/Http/Controllers/Admin/ApiController.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class ApiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Updates a component with the entered info.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function postUpdateComponent(Component $component)
|
||||
{
|
||||
if (!$component->update(Binput::except(['_token']))) {
|
||||
throw new Exception(trans('dashboard.components.edit.failure'));
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a components ordering.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function postUpdateComponentOrder()
|
||||
{
|
||||
$componentData = Binput::all();
|
||||
unset($componentData['component'][0]); // Remove random 0 index.
|
||||
|
||||
foreach ($componentData['component'] as $componentId => $order) {
|
||||
$component = Component::find($componentId);
|
||||
$component->update(['order' => $order]);
|
||||
}
|
||||
|
||||
return $componentData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a template by slug.
|
||||
*
|
||||
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\IncidentTemplate
|
||||
*/
|
||||
public function getIncidentTemplate()
|
||||
{
|
||||
$templateSlug = Binput::get('slug');
|
||||
|
||||
$template = IncidentTemplate::where('slug', $templateSlug)->first();
|
||||
|
||||
if ($template) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
throw new ModelNotFoundException('Incident template for '.$templateSlug.' could not be found.');
|
||||
}
|
||||
}
|
||||
373
app/Http/Controllers/Admin/ComponentController.php
Normal file
373
app/Http/Controllers/Admin/ComponentController.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Tag;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class ComponentController extends Controller
|
||||
{
|
||||
protected $subMenu = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'components' => [
|
||||
'title' => trans('dashboard.components.components'),
|
||||
'url' => route('dashboard.components'),
|
||||
'icon' => 'ion-outlet',
|
||||
'active' => false,
|
||||
],
|
||||
'groups' => [
|
||||
'title' => trans_choice('dashboard.components.groups.groups', 2),
|
||||
'url' => route('dashboard.components.groups'),
|
||||
'icon' => 'ion-folder',
|
||||
'active' => false,
|
||||
],
|
||||
];
|
||||
|
||||
View::share([
|
||||
'subMenu' => $this->subMenu,
|
||||
'subTitle' => trans_choice('dashboard.components.components', 2),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the components view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showComponents()
|
||||
{
|
||||
$components = Component::orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
$this->subMenu['components']['active'] = true;
|
||||
|
||||
return View::make('dashboard.components.index')->with([
|
||||
'pageTitle' => trans_choice('dashboard.components.components', 2).' - '.trans('dashboard.dashboard'),
|
||||
'components' => $components,
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the component groups view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showComponentGroups()
|
||||
{
|
||||
$this->subMenu['groups']['active'] = true;
|
||||
|
||||
return View::make('dashboard.components.groups.index')->with([
|
||||
'pageTitle' => trans_choice('dashboard.components.groups.groups', 2).' - '.trans('dashboard.dashboard'),
|
||||
'groups' => ComponentGroup::all(),
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit component view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditComponent(Component $component)
|
||||
{
|
||||
$groups = ComponentGroup::all();
|
||||
|
||||
$pageTitle = sprintf(
|
||||
'"%s" - %s - %s',
|
||||
$component->name,
|
||||
trans('dashboard.components.edit.title'),
|
||||
trans('dashboard.dashboard')
|
||||
);
|
||||
|
||||
return View::make('dashboard.components.edit')->with([
|
||||
'pageTitle' => $pageTitle,
|
||||
'component' => $component,
|
||||
'groups' => $groups,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a component.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function updateComponentAction(Component $component)
|
||||
{
|
||||
$_component = Binput::get('component');
|
||||
$_component['user_id'] = Auth::user()->id;
|
||||
$tags = array_pull($_component, 'tags');
|
||||
|
||||
$component->update($_component);
|
||||
|
||||
if (! $component->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
$tags = preg_split('/ ?, ?/', $tags);
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add component view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddComponent()
|
||||
{
|
||||
$groups = ComponentGroup::all();
|
||||
|
||||
return View::make('dashboard.components.add')->with([
|
||||
'pageTitle' => trans('dashboard.components.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'groups' => $groups,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new component.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createComponentAction()
|
||||
{
|
||||
$_component = Binput::get('component');
|
||||
$_component['user_id'] = Auth::user()->id;
|
||||
// We deal with tags separately.
|
||||
$tags = array_pull($_component, 'tags');
|
||||
|
||||
$component = Component::create($_component);
|
||||
|
||||
if (! $component->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
$tags = preg_split('/ ?, ?/', $tags);
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given component.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Component $component
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteComponentAction(Component $component)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Component',
|
||||
]);
|
||||
|
||||
$component->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given component group.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteComponentGroupAction(ComponentGroup $group)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Component Group',
|
||||
]);
|
||||
|
||||
$group->components->map(function ($component) {
|
||||
$component->update([
|
||||
'group_id' => 0,
|
||||
]);
|
||||
});
|
||||
|
||||
$group->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add component group view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddComponentGroup()
|
||||
{
|
||||
return View::make('dashboard.components.groups.add')->with([
|
||||
'pageTitle' => trans('dashboard.components.groups.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit component group view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditComponentGroup(ComponentGroup $group)
|
||||
{
|
||||
return View::make('dashboard.components.groups.edit')->with([
|
||||
'pageTitle' => trans('dashboard.components.groups.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'group' => $group,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new component.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postAddComponentGroup()
|
||||
{
|
||||
$group = ComponentGroup::create(Binput::get('group'));
|
||||
|
||||
if (! $group->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component Group',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Component Group',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.groups.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a component group.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function updateComponentGroupAction(ComponentGroup $group)
|
||||
{
|
||||
$groupData = Binput::get('group');
|
||||
$group->update($groupData);
|
||||
|
||||
if (! $group->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component Group',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.components.groups.edit.failure')
|
||||
))
|
||||
->with('errors', $group->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edit Component Group',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.components.groups.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
}
|
||||
36
app/Http/Controllers/Admin/DashboardController.php
Normal file
36
app/Http/Controllers/Admin/DashboardController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the dashboard view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showDashboard()
|
||||
{
|
||||
$components = Component::all();
|
||||
|
||||
return View::make('dashboard.index')->with([
|
||||
'components' => $components,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the notifications view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showNotifications()
|
||||
{
|
||||
return View::make('dashboard.notifications.index')->with([
|
||||
'pageTitle' => trans('dashboard.notifications.notifications').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
317
app/Http/Controllers/Admin/IncidentController.php
Normal file
317
app/Http/Controllers/Admin/IncidentController.php
Normal file
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class IncidentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Stores the sub-sidebar tree list.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $subMenu = [];
|
||||
|
||||
/**
|
||||
* Creates a new DashIncidentController instance.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Http\Controllers\DashScheduleController
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'incidents' => [
|
||||
'title' => trans('dashboard.incidents.incidents'),
|
||||
'url' => route('dashboard.incidents'),
|
||||
'icon' => 'ion-android-checkmark-circle',
|
||||
'active' => true,
|
||||
],
|
||||
'schedule' => [
|
||||
'title' => trans('dashboard.schedule.schedule'),
|
||||
'url' => route('dashboard.schedule'),
|
||||
'icon' => 'ion-android-calendar',
|
||||
'active' => false,
|
||||
],
|
||||
];
|
||||
|
||||
View::share('subMenu', $this->subMenu);
|
||||
View::share('subTitle', trans('dashboard.incidents.title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the incidents view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIncidents()
|
||||
{
|
||||
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
|
||||
|
||||
return View::make('dashboard.incidents.index')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.incidents').' - '.trans('dashboard.dashboard'),
|
||||
'incidents' => $incidents,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add incident view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddIncident()
|
||||
{
|
||||
return View::make('dashboard.incidents.add')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'components' => Component::all(),
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the incident templates.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTemplates()
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.index')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.title').' - '.trans('dashboard.dashboard'),
|
||||
'incidentTemplates' => IncidentTemplate::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incident.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createIncidentAction()
|
||||
{
|
||||
$incidentData = Binput::get('incident');
|
||||
$incidentData['user_id'] = Auth::user()->id;
|
||||
$componentStatus = array_pull($incidentData, 'component_status');
|
||||
|
||||
$incident = Incident::create($incidentData);
|
||||
|
||||
if (! $incident->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
// Update the component.
|
||||
if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) {
|
||||
Component::find($incidentData['component_id'])->update([
|
||||
'status' => $componentStatus,
|
||||
]);
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add incident template view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddIncidentTemplate()
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.add')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit incident template view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
return View::make('dashboard.incidents.templates.edit')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.templates.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'template' => $template,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an incident template.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Incident Template',
|
||||
]);
|
||||
|
||||
$template->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incident template.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createIncidentTemplateAction()
|
||||
{
|
||||
$_template = Binput::get('template');
|
||||
$template = IncidentTemplate::create($_template);
|
||||
|
||||
if (! $template->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident Template',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Incident Template',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.templates.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteIncidentAction(Incident $incident)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Incident',
|
||||
]);
|
||||
|
||||
$incident->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit incident view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditIncidentAction(Incident $incident)
|
||||
{
|
||||
return View::make('dashboard.incidents.edit')->with([
|
||||
'pageTitle' => trans('dashboard.incidents.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'incident' => $incident,
|
||||
'components' => Component::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $incident
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editIncidentAction(Incident $incident)
|
||||
{
|
||||
$incidentData = Binput::get('incident');
|
||||
$incidentData['user_id'] = Auth::user()->id;
|
||||
$incident->update($incidentData);
|
||||
|
||||
if (! $incident->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Incident',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Incident',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.incidents.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/incidents')->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an incident template.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $template
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editTemplateAction(IncidentTemplate $template)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Incident Template',
|
||||
]);
|
||||
|
||||
$template->update(Binput::get('template'));
|
||||
|
||||
return Redirect::back()->with('updatedTemplate', $template);
|
||||
}
|
||||
}
|
||||
203
app/Http/Controllers/Admin/MetricController.php
Normal file
203
app/Http/Controllers/Admin/MetricController.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use CachetHQ\Cachet\Models\MetricPoint;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class MetricController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the metrics view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetrics()
|
||||
{
|
||||
$metrics = Metric::orderBy('created_at', 'desc')->get();
|
||||
|
||||
return View::make('dashboard.metrics.index')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.metrics').' - '.trans('dashboard.dashboard'),
|
||||
'metrics' => $metrics,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add metric view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddMetric()
|
||||
{
|
||||
return View::make('dashboard.metrics.add')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'metricMetricPoints' => MetricPoint::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the metric points.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showMetricPoints()
|
||||
{
|
||||
return View::make('dashboard.metrics.points.index')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.points.title').' - '.trans('dashboard.dashboard'),
|
||||
'metricMetricPoints' => MetricPoint::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new metric.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createMetricAction()
|
||||
{
|
||||
$metricData = Binput::get('metric');
|
||||
$metric = Metric::create($metricData);
|
||||
|
||||
if (! $metric->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Metric',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.metrics.add.failure')
|
||||
))
|
||||
->with('errors', $metric->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Metric',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add metric point view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddMetricPoint()
|
||||
{
|
||||
return View::make('dashboard.metrics.points.add')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.points.add.title').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new metric point.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createMetricPointAction()
|
||||
{
|
||||
$_point = Binput::get('point');
|
||||
$point = MetricPoint::create($_point);
|
||||
|
||||
if (! $point->isValid()) {
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.points.add.failure')
|
||||
))
|
||||
->with('errors', $point->getErrors());
|
||||
}
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.points.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given metric.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteMetricAction(Metric $metric)
|
||||
{
|
||||
$metric->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit metric view.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditMetricAction(Metric $metric)
|
||||
{
|
||||
return View::make('dashboard.metrics.edit')->with([
|
||||
'pageTitle' => trans('dashboard.metrics.edit.title').' - '.trans('dashboard.dashboard'),
|
||||
'metric' => $metric,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an metric.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Metric $metric
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editMetricAction(Metric $metric)
|
||||
{
|
||||
$_metric = Binput::get('metric');
|
||||
$metric->update($_metric);
|
||||
|
||||
if (! $metric->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Metric',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong>',
|
||||
trans('dashboard.notifications.awesome')
|
||||
))
|
||||
->with('errors', $metric->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Metric',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.metrics.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/metrics')->with('success', $successMsg);
|
||||
}
|
||||
}
|
||||
233
app/Http/Controllers/Admin/ScheduleController.php
Normal file
233
app/Http/Controllers/Admin/ScheduleController.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class ScheduleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Stores the sub-sidebar tree list.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $subMenu = [];
|
||||
|
||||
/**
|
||||
* Creates a new DashScheduleController instance.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Http\Controllers\DashScheduleController
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// TODO: Remove this from DashIncidentController, so it's shared?
|
||||
$this->subMenu = [
|
||||
'incidents' => [
|
||||
'title' => trans('dashboard.incidents.incidents'),
|
||||
'url' => route('dashboard.incidents'),
|
||||
'icon' => 'ion-android-checkmark-circle',
|
||||
'active' => false,
|
||||
],
|
||||
'schedule' => [
|
||||
'title' => trans('dashboard.schedule.schedule'),
|
||||
'url' => route('dashboard.schedule'),
|
||||
'icon' => 'ion-android-calendar',
|
||||
'active' => true,
|
||||
],
|
||||
];
|
||||
|
||||
View::share('subMenu', $this->subMenu);
|
||||
View::share('subTitle', trans('dashboard.incidents.title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all scheduled maintenance.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIndex()
|
||||
{
|
||||
$schedule = Incident::scheduled()->orderBy('created_at')->get();
|
||||
|
||||
return View::make('dashboard.schedule.index')->withSchedule($schedule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add schedule maintenance form.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddSchedule()
|
||||
{
|
||||
$incidentTemplates = IncidentTemplate::all();
|
||||
|
||||
return View::make('dashboard.schedule.add')->with([
|
||||
'incidentTemplates' => $incidentTemplates,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new scheduled maintenance "incident".
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function addScheduleAction()
|
||||
{
|
||||
$scheduleData = Binput::get('incident');
|
||||
$scheduleData['user_id'] = Auth::user()->id;
|
||||
// Parse the schedule date.
|
||||
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))
|
||||
->setTimezone(Config::get('app.timezone'));
|
||||
|
||||
if ($scheduledAt->isPast()) {
|
||||
$messageBag = new MessageBag();
|
||||
$messageBag->add('scheduled_at', trans('validation.date', [
|
||||
'attribute' => 'scheduled time you supplied',
|
||||
]));
|
||||
|
||||
return Redirect::back()->withErrors($messageBag);
|
||||
}
|
||||
|
||||
$scheduleData['scheduled_at'] = $scheduledAt;
|
||||
// Bypass the incident.status field.
|
||||
$scheduleData['status'] = 0;
|
||||
|
||||
$incident = Incident::create($scheduleData);
|
||||
|
||||
if (! $incident->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Scheduled Maintenance',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('success', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.schedule.add.failure')
|
||||
))
|
||||
->with('errors', $incident->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Scheduled Maintenance',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.schedule.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the edit schedule maintenance form.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showEditSchedule(Incident $schedule)
|
||||
{
|
||||
$incidentTemplates = IncidentTemplate::all();
|
||||
|
||||
return View::make('dashboard.schedule.edit')->with([
|
||||
'incidentTemplates' => $incidentTemplates,
|
||||
'schedule' => $schedule,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the given incident.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function editScheduleAction(Incident $schedule)
|
||||
{
|
||||
$scheduleData = Binput::get('incident');
|
||||
$scheduleData['user_id'] = Auth::user()->id;
|
||||
// Parse the schedule date.
|
||||
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))
|
||||
->setTimezone(Config::get('app.timezone'));
|
||||
|
||||
if ($scheduledAt->isPast()) {
|
||||
$messageBag = new MessageBag();
|
||||
$messageBag->add('scheduled_at', trans('validation.date', [
|
||||
'attribute' => 'scheduled time you supplied',
|
||||
]));
|
||||
|
||||
return Redirect::back()->withErrors($messageBag);
|
||||
}
|
||||
|
||||
$scheduleData['scheduled_at'] = $scheduledAt;
|
||||
// Bypass the incident.status field.
|
||||
$scheduleData['status'] = 0;
|
||||
|
||||
$schedule->update($scheduleData);
|
||||
|
||||
if (! $schedule->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Schedule',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.schedule.edit.failure')
|
||||
))
|
||||
->with('errors', $schedule->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Edited Schedule',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.schedule.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::to('dashboard/schedule')->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a given schedule.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Incident $schedule
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteScheduleAction(Incident $schedule)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Schedule',
|
||||
]);
|
||||
|
||||
$schedule->delete();
|
||||
|
||||
return Redirect::back()->with('warning', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.schedule.delete.failure')
|
||||
));
|
||||
}
|
||||
}
|
||||
180
app/Http/Controllers/Admin/SettingsController.php
Normal file
180
app/Http/Controllers/Admin/SettingsController.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use CachetHQ\Cachet\Controllers\AbstractController;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class SettingsController extends AbstractController
|
||||
{
|
||||
protected $subMenu = [];
|
||||
protected $subTitle = 'Settings';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->subMenu = [
|
||||
'setup' => [
|
||||
'title' => trans('dashboard.settings.app-setup.app-setup'),
|
||||
'url' => '/dashboard/settings/setup',
|
||||
'icon' => 'ion-gear-b',
|
||||
'active' => false,
|
||||
],
|
||||
'security' => [
|
||||
'title' => trans('dashboard.settings.security.security'),
|
||||
'url' => '/dashboard/settings/security',
|
||||
'icon' => 'ion-lock-combination',
|
||||
'active' => false,
|
||||
],
|
||||
'theme' => [
|
||||
'title' => trans('dashboard.settings.theme.theme'),
|
||||
'url' => '/dashboard/settings/theme',
|
||||
'icon' => 'ion-paintbrush',
|
||||
'active' => false,
|
||||
],
|
||||
'stylesheet' => [
|
||||
'title' => trans('dashboard.settings.stylesheet.stylesheet'),
|
||||
'url' => '/dashboard/settings/stylesheet',
|
||||
'icon' => 'ion-paintbucket',
|
||||
'active' => false,
|
||||
],
|
||||
];
|
||||
|
||||
View::share('subTitle', $this->subTitle);
|
||||
|
||||
View::share('subMenu', $this->subMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings setup view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showSetupView()
|
||||
{
|
||||
$this->subMenu['setup']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.app-setup')->with([
|
||||
'pageTitle' => 'Application Setup - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings theme view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showThemeView()
|
||||
{
|
||||
$this->subMenu['theme']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.theme')->with([
|
||||
'pageTitle' => 'Theme - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings security view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showSecurityView()
|
||||
{
|
||||
$this->subMenu['security']['active'] = true;
|
||||
|
||||
$unsecureUsers = User::whereNull('google_2fa_secret')->orWhere('google_2fa_secret', '')->get();
|
||||
|
||||
return View::make('dashboard.settings.security')->with([
|
||||
'pageTitle' => 'Security - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
'unsecureUsers' => $unsecureUsers,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings stylesheet view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showStylesheetView()
|
||||
{
|
||||
$this->subMenu['stylesheet']['active'] = true;
|
||||
|
||||
return View::make('dashboard.settings.stylesheet')->with([
|
||||
'pageTitle' => 'Stylesheet - Dashboard',
|
||||
'subMenu' => $this->subMenu,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the status page settings.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postSettings()
|
||||
{
|
||||
if (Binput::get('remove_banner') === '1') {
|
||||
$setting = Setting::where('name', 'app_banner');
|
||||
$setting->delete();
|
||||
}
|
||||
|
||||
if (Binput::hasFile('app_banner')) {
|
||||
$file = Binput::file('app_banner');
|
||||
|
||||
// Image Validation.
|
||||
// Image size in bytes.
|
||||
$maxSize = $file->getMaxFilesize();
|
||||
|
||||
if ($file->getSize() > $maxSize) {
|
||||
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.too-big', [
|
||||
'size' => $maxSize,
|
||||
]));
|
||||
}
|
||||
|
||||
if (!$file->isValid() || $file->getError()) {
|
||||
return Redirect::back()->withErrors($file->getErrorMessage());
|
||||
}
|
||||
|
||||
if (strpos($file->getMimeType(), 'image/') !== 0) {
|
||||
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.images-only'));
|
||||
}
|
||||
|
||||
// Store the banner.
|
||||
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(),
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) {
|
||||
Setting::firstOrCreate([
|
||||
'name' => $settingName,
|
||||
])->update([
|
||||
'value' => $settingValue,
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure'));
|
||||
}
|
||||
|
||||
Lang::setLocale(Binput::get('app_locale'));
|
||||
|
||||
return Redirect::back()->with('success', trans('dashboard.settings.edit.success'));
|
||||
}
|
||||
}
|
||||
138
app/Http/Controllers/Admin/TeamController.php
Normal file
138
app/Http/Controllers/Admin/TeamController.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
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 TeamController 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()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Added User',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()->withInput(Binput::except('password'))
|
||||
->with('title', sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.team.add.failure')
|
||||
))
|
||||
->with('errors', $user->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Added User',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.team.add.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']);
|
||||
}
|
||||
|
||||
$user->update($items);
|
||||
|
||||
if (! $user->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Updated User',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Updated User',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.team.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
}
|
||||
98
app/Http/Controllers/Admin/UserController.php
Normal file
98
app/Http/Controllers/Admin/UserController.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use PragmaRX\Google2FA\Vendor\Laravel\Facade as Google2FA;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Shows the user view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showUser()
|
||||
{
|
||||
return View::make('dashboard.user.index')->with([
|
||||
'pageTitle' => trans('dashboard.team.profile').' - '.trans('dashboard.dashboard'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current user.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function postUser()
|
||||
{
|
||||
$items = Binput::all();
|
||||
|
||||
$passwordChange = array_get($items, 'password');
|
||||
$enable2FA = (bool) array_pull($items, 'google2fa');
|
||||
|
||||
// Let's enable/disable auth
|
||||
if ($enable2FA && ! Auth::user()->hasTwoFactor) {
|
||||
$items['google_2fa_secret'] = Google2FA::generateSecretKey();
|
||||
|
||||
segment_track('User Management', [
|
||||
'event' => 'enabled_two_factor',
|
||||
'value' => true,
|
||||
]);
|
||||
} elseif (! $enable2FA) {
|
||||
$items['google_2fa_secret'] = '';
|
||||
|
||||
segment_track('User Management', [
|
||||
'event' => 'enabled_two_factor',
|
||||
'value' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
if (trim($passwordChange) === '') {
|
||||
unset($items['password']);
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
$user->update($items);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
$successMsg = sprintf(
|
||||
'<strong>%s</strong> %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.team.edit.success')
|
||||
);
|
||||
|
||||
return Redirect::back()->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerates the users API key.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function regenerateApiKey(User $user)
|
||||
{
|
||||
segment_track('User Management', [
|
||||
'event' => 'regenrated_api_token',
|
||||
]);
|
||||
|
||||
$user->api_key = User::generateApiKey();
|
||||
$user->save();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
}
|
||||
160
app/Http/Controllers/Api/AbstractApiController.php
Normal file
160
app/Http/Controllers/Api/AbstractApiController.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Http\Controllers\AbstractController as BaseController;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
abstract class AbstractApiController extends BaseController
|
||||
{
|
||||
/**
|
||||
* The HTTP response headers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $headers = [];
|
||||
|
||||
/**
|
||||
* The HTTP response meta data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $meta = [];
|
||||
|
||||
/**
|
||||
* The HTTP response data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* The HTTP response status code.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $statusCode = 200;
|
||||
|
||||
/**
|
||||
* Set the response headers.
|
||||
*
|
||||
* @param array $headers
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setHeaders(array $headers)
|
||||
{
|
||||
$this->headers = $headers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the response meta data.
|
||||
*
|
||||
* @param array $meta
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setMetaData(array $meta)
|
||||
{
|
||||
$this->meta = $meta;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the response meta data.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setData(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the response status code.
|
||||
*
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setStatusCode($satusCode)
|
||||
{
|
||||
$this->satusCode = $satusCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with a pagination response.
|
||||
*
|
||||
* @param \Illuminate\Pagination\Paginator $paginator
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
protected function paginator(Paginator $paginator, Request $request)
|
||||
{
|
||||
foreach ($request->query as $key => $value) {
|
||||
if ($key != 'page') {
|
||||
$paginator->addQuery($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$pagination = [
|
||||
'pagination' => [
|
||||
'total' => $paginator->total(),
|
||||
'count' => count($paginator->items()),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'total_pages' => $paginator->lastPage(),
|
||||
'links' => [
|
||||
'next_page' => $paginator->nextPageUrl(),
|
||||
'previous_page' => $paginator->previousPageUrl(),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $this->setMetaData($pagination)->setData($paginator->items())->respond();
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with a no content response.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
protected function noContent()
|
||||
{
|
||||
return $this->setStatusCode(204)->respond();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the response.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function respond()
|
||||
{
|
||||
if (! empty($this->meta)) {
|
||||
$response['meta'] = $this->meta;
|
||||
}
|
||||
|
||||
$response['data'] = $this->data;
|
||||
|
||||
if ($this->data instanceof Arrayable) {
|
||||
$response['data'] = $this->data->toArray();
|
||||
}
|
||||
|
||||
return Response::json($response, $this->statusCode, $this->headers);
|
||||
}
|
||||
}
|
||||
124
app/Http/Controllers/Api/ComponentController.php
Normal file
124
app/Http/Controllers/Api/ComponentController.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Models\Tag;
|
||||
use CachetHQ\Cachet\Repositories\Component\ComponentRepository;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ComponentController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The component repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Component\ComponentRepository
|
||||
*/
|
||||
protected $component;
|
||||
|
||||
/**
|
||||
* Create a new component controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Component\ComponentRepository $component
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(ComponentRepository $component)
|
||||
{
|
||||
$this->component = $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all components.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getComponents(Request $request)
|
||||
{
|
||||
$components = $this->component->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($components, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single component.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function getComponent($id)
|
||||
{
|
||||
return $this->component->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new component.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function postComponents()
|
||||
{
|
||||
$component = $this->component->create(
|
||||
$this->auth->user()->id,
|
||||
Binput::except('tags')
|
||||
);
|
||||
|
||||
if (Binput::has('tags')) {
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing component.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Component
|
||||
*/
|
||||
public function putComponent($id)
|
||||
{
|
||||
$component = $this->component->update($id, Binput::except('tags'));
|
||||
|
||||
if (Binput::has('tags')) {
|
||||
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing component.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function deleteComponent($id)
|
||||
{
|
||||
$this->component->destroy($id);
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
}
|
||||
89
app/Http/Controllers/Api/IncidentController.php
Normal file
89
app/Http/Controllers/Api/IncidentController.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Incident\IncidentRepository;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IncidentController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The incident repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Incident\IncidentRepository
|
||||
*/
|
||||
protected $incident;
|
||||
|
||||
/**
|
||||
* Create a new incident controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Incident\IncidentRepository $incident
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(IncidentRepository $incident)
|
||||
{
|
||||
$this->incident = $incident;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all incidents.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getIncidents(Request $request)
|
||||
{
|
||||
$incidents = $this->incident->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($incidents, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function getIncident($id)
|
||||
{
|
||||
return $this->incident->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new incident.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function postIncidents()
|
||||
{
|
||||
return $this->incident->create($this->auth->user()->id, Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Incident
|
||||
*/
|
||||
public function putIncident($id)
|
||||
{
|
||||
return $this->incident->update($id, Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing incident.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function deleteIncident($id)
|
||||
{
|
||||
$this->incident->destroy($id);
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
}
|
||||
101
app/Http/Controllers/Api/MetricController.php
Normal file
101
app/Http/Controllers/Api/MetricController.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MetricController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The metric repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\Metric\MetricRepository
|
||||
*/
|
||||
protected $metric;
|
||||
|
||||
/**
|
||||
* Create a new metric controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\Metric\MetricRepository $metric
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MetricRepository $metric)
|
||||
{
|
||||
$this->metric = $metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all metrics.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetrics(Request $request)
|
||||
{
|
||||
$metrics = $this->metric->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($metrics, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function getMetric($id)
|
||||
{
|
||||
return $this->metric->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all metric points.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getMetricPoints($id)
|
||||
{
|
||||
return $this->metric->points($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric.
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function postMetrics()
|
||||
{
|
||||
return $this->metric->create(Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\Metric
|
||||
*/
|
||||
public function putMetric($id)
|
||||
{
|
||||
return $this->metric->update($id, Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing metric.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function deleteMetric($id)
|
||||
{
|
||||
$this->metric->destroy($id);
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
}
|
||||
83
app/Http/Controllers/Api/MetricPointController.php
Normal file
83
app/Http/Controllers/Api/MetricPointController.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
|
||||
class MetricPointController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* The metric point repository instance.
|
||||
*
|
||||
* @var \CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository
|
||||
*/
|
||||
protected $metricPoint;
|
||||
|
||||
/**
|
||||
* Create a new metric point controller instance.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Repositories\MetricPoint\MetricPointRepository $metricPoint
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(MetricPointRepository $metricPoint)
|
||||
{
|
||||
$this->metricPoint = $metricPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single metric point.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function getMetricPoints($id)
|
||||
{
|
||||
return $this->metricPoint->findOrFail($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new metric point.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function postMetricPoints($id)
|
||||
{
|
||||
return $this->metricPoint->create($id, Binput::all());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a metric point.
|
||||
*
|
||||
* @param int $metricId
|
||||
* @param int $pointId
|
||||
*
|
||||
* @return \CachetHQ\Cachet\Models\MetricPoint
|
||||
*/
|
||||
public function putMetricPoint($metricId, $pointId)
|
||||
{
|
||||
$metricPoint = $this->metricPoint->findOrFail($pointId);
|
||||
$metricPoint->update(Binput::all());
|
||||
|
||||
return $metricPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a metric point.
|
||||
*
|
||||
* @param int $metricId
|
||||
* @param int $pointId
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function deleteMetricPoint($metricId, $pointId)
|
||||
{
|
||||
$this->metricPoint->destroy($pointId);
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
}
|
||||
46
app/Http/Controllers/AtomController.php
Normal file
46
app/Http/Controllers/AtomController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Roumen\Feed\Facades\Feed;
|
||||
|
||||
class AtomController extends Controller
|
||||
{
|
||||
/**
|
||||
* Generates an Atom feed of all incidents.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function feedAction()
|
||||
{
|
||||
$feed = Feed::make();
|
||||
$feed->title = Setting::get('app_name');
|
||||
$feed->description = trans('cachet.feed');
|
||||
$feed->link = Setting::get('app_domain');
|
||||
|
||||
$feed->setDateFormat('datetime');
|
||||
|
||||
Incident::all()->map(function ($incident) use ($feed) {
|
||||
if ($incident->component) {
|
||||
$componentName = $incident->component->name;
|
||||
} else {
|
||||
$componentName = null;
|
||||
}
|
||||
|
||||
$feed->add(
|
||||
$incident->name,
|
||||
Setting::get('app_name'),
|
||||
Setting::get('app_domain'),
|
||||
$incident->created_at,
|
||||
($componentName === null ? $incident->humanStatus : $componentName.' '.$incident->humanStatus),
|
||||
$incident->message
|
||||
);
|
||||
});
|
||||
|
||||
return $feed->render('atom');
|
||||
}
|
||||
}
|
||||
38
app/Http/Controllers/Auth/AuthController.php
Normal file
38
app/Http/Controllers/Auth/AuthController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php namespace CachetHQ\Cachet\Http\Controllers\Auth;
|
||||
|
||||
use CachetHQ\Cachet\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Auth\Registrar;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Registration & Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users, as well as the
|
||||
| authentication of existing users. By default, this controller uses
|
||||
| a simple trait to add these behaviors. Why don't you explore it?
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesAndRegistersUsers;
|
||||
|
||||
/**
|
||||
* Create a new authentication controller instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Guard $auth
|
||||
* @param \Illuminate\Contracts\Auth\Registrar $registrar
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth, Registrar $registrar)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->registrar = $registrar;
|
||||
|
||||
$this->middleware('guest', ['except' => 'getLogout']);
|
||||
}
|
||||
}
|
||||
38
app/Http/Controllers/Auth/PasswordController.php
Normal file
38
app/Http/Controllers/Auth/PasswordController.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php namespace CachetHQ\Cachet\Http\Controllers\Auth;
|
||||
|
||||
use CachetHQ\Cachet\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Auth\PasswordBroker;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Create a new password controller instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Guard $auth
|
||||
* @param \Illuminate\Contracts\Auth\PasswordBroker $passwords
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Guard $auth, PasswordBroker $passwords)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->passwords = $passwords;
|
||||
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
115
app/Http/Controllers/AuthController.php
Normal file
115
app/Http/Controllers/AuthController.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use GrahamCampbell\Throttle\Facades\Throttle;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
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 Controller
|
||||
{
|
||||
/**
|
||||
* Shows the login view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showLogin()
|
||||
{
|
||||
return View::make('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the user in.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postLogin()
|
||||
{
|
||||
$loginData = Binput::only(['email', 'password']);
|
||||
// Validate login credentials.
|
||||
if (Auth::validate($loginData)) {
|
||||
// Log the user in for one request.
|
||||
Auth::once($loginData);
|
||||
// Do we have Two Factor Auth enabled?
|
||||
if (Auth::user()->hasTwoFactor) {
|
||||
// Temporarily store the user.
|
||||
Session::put('2fa_id', Auth::user()->id);
|
||||
|
||||
return Redirect::route('two-factor');
|
||||
}
|
||||
|
||||
// We probably wan't to add support for "Remember me" here.
|
||||
Auth::attempt(Binput::only(['email', 'password']));
|
||||
|
||||
return Redirect::intended('dashboard');
|
||||
}
|
||||
|
||||
Throttle::hit(Request::instance(), 10, 10);
|
||||
|
||||
return Redirect::back()
|
||||
->withInput(Binput::except('password'))
|
||||
->with('error', trans('forms.login.invalid'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the two-factor-auth view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showTwoFactorAuth()
|
||||
{
|
||||
return View::make('auth.two-factor-auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the Two Factor token.
|
||||
*
|
||||
* This feels very hacky, but we have to juggle authentication and codes.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postTwoFactor()
|
||||
{
|
||||
// Check that we have a session.
|
||||
if ($userId = Session::pull('2fa_id')) {
|
||||
$code = Binput::get('code');
|
||||
|
||||
// Maybe a temp login here.
|
||||
Auth::loginUsingId($userId);
|
||||
|
||||
$valid = Google2FA::verifyKey(Auth::user()->google_2fa_secret, $code);
|
||||
|
||||
if ($valid) {
|
||||
return Redirect::intended('dashboard');
|
||||
} else {
|
||||
// Failed login, log back out.
|
||||
Auth::logout();
|
||||
|
||||
return Redirect::route('login')->with('error', trans('forms.login.invalid-token'));
|
||||
}
|
||||
}
|
||||
|
||||
return Redirect::route('login')->with('error', trans('forms.login.invalid-token'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the user out, deleting their session etc.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function logoutAction()
|
||||
{
|
||||
Auth::logout();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
109
app/Http/Controllers/HomeController.php
Normal file
109
app/Http/Controllers/HomeController.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Component;
|
||||
use CachetHQ\Cachet\Models\ComponentGroup;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use CachetHQ\Cachet\Models\Metric;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Returns the rendered Blade templates.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showIndex()
|
||||
{
|
||||
$today = Carbon::now();
|
||||
$startDate = Carbon::now();
|
||||
|
||||
segment_track('Status Page', [
|
||||
'event' => 'Landed',
|
||||
]);
|
||||
|
||||
// Check if we have another starting date
|
||||
if (Binput::has('start_date')) {
|
||||
try {
|
||||
// If date provided is valid
|
||||
$oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
|
||||
|
||||
segment_track('Status Page', [
|
||||
'start_date' => $oldDate->format('Y-m-d'),
|
||||
]);
|
||||
|
||||
if (Setting::get('app_tracking')) {
|
||||
Segment::track([
|
||||
'userId' => Config::get('app.key'),
|
||||
'event' => 'Home Page',
|
||||
'properties' => [
|
||||
'start_date' => $oldDate,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// If trying to get a future date fallback to today
|
||||
if ($today->gt($oldDate)) {
|
||||
$startDate = $oldDate;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Fallback to today
|
||||
}
|
||||
}
|
||||
|
||||
$metrics = null;
|
||||
|
||||
if ($displayMetrics = Setting::get('display_graphs')) {
|
||||
$metrics = Metric::where('display_chart', 1)->get();
|
||||
}
|
||||
|
||||
$allIncidents = [];
|
||||
$daysToShow = Setting::get('app_incident_days') ?: 7;
|
||||
$incidentDays = range(0, $daysToShow);
|
||||
$dateFormat = Setting::get('date_format') ?: 'jS F Y';
|
||||
|
||||
foreach ($incidentDays as $i) {
|
||||
$date = $startDate->copy()->subDays($i);
|
||||
|
||||
$incidents = Incident::notScheduled()->whereBetween('created_at', [
|
||||
$date->format('Y-m-d').' 00:00:00',
|
||||
$date->format('Y-m-d').' 23:59:59',
|
||||
])->orderBy('created_at', 'desc')->get();
|
||||
|
||||
$allIncidents[] = [
|
||||
'date' => (new Date($date->toDateString()))->format($dateFormat),
|
||||
'incidents' => $incidents,
|
||||
];
|
||||
}
|
||||
|
||||
// Scheduled maintenance code.
|
||||
$scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
|
||||
|
||||
// Component & Component Group lists.
|
||||
$usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
|
||||
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->get();
|
||||
$ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
|
||||
|
||||
return View::make('index', [
|
||||
'componentGroups' => $componentGroups,
|
||||
'ungroupedComponents' => $ungroupedComponents,
|
||||
'displayMetrics' => $displayMetrics,
|
||||
'metrics' => $metrics,
|
||||
'allIncidents' => $allIncidents,
|
||||
'scheduledMaintenance' => $scheduledMaintenance,
|
||||
'pageTitle' => Setting::get('app_name'),
|
||||
'aboutApp' => Markdown::convertToHtml(Setting::get('app_about')),
|
||||
'canPageForward' => (bool) $today->gt($startDate),
|
||||
'previousDate' => $startDate->copy()->subWeek()->subDay()->toDateString(),
|
||||
'nextDate' => $startDate->copy()->addWeek()->addDay()->toDateString(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
46
app/Http/Controllers/RssController.php
Normal file
46
app/Http/Controllers/RssController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Roumen\Feed\Facades\Feed;
|
||||
|
||||
class RssController extends Controller
|
||||
{
|
||||
/**
|
||||
* Generates an RSS feed of all incidents.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function feedAction()
|
||||
{
|
||||
$feed = Feed::make();
|
||||
$feed->title = Setting::get('app_name');
|
||||
$feed->description = trans('cachet.feed');
|
||||
$feed->link = Setting::get('app_domain');
|
||||
|
||||
$feed->setDateFormat('datetime');
|
||||
|
||||
Incident::all()->map(function ($incident) use ($feed) {
|
||||
if ($incident->component) {
|
||||
$componentName = $incident->component->name;
|
||||
} else {
|
||||
$componentName = null;
|
||||
}
|
||||
|
||||
$feed->add(
|
||||
$incident->name,
|
||||
Setting::get('app_name'),
|
||||
Setting::get('app_domain'),
|
||||
$incident->created_at,
|
||||
($componentName === null ? $incident->humanStatus : $componentName.' '.$incident->humanStatus),
|
||||
$incident->message
|
||||
);
|
||||
});
|
||||
|
||||
return $feed->render('rss');
|
||||
}
|
||||
}
|
||||
152
app/Http/Controllers/SetupController.php
Normal file
152
app/Http/Controllers/SetupController.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers;
|
||||
|
||||
use CachetHQ\Cachet\Models\Setting;
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class SetupController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Create a new setup controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->beforeFilter('csrf', ['only' => ['postCachet']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the setup page.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function getIndex()
|
||||
{
|
||||
return View::make('setup')->with([
|
||||
'pageTitle' => trans('setup.setup'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles validation on step one of setup form.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function postStep1()
|
||||
{
|
||||
$postData = Binput::all();
|
||||
|
||||
segment_track('Setup', [
|
||||
'step' => '1',
|
||||
]);
|
||||
|
||||
$v = Validator::make($postData, [
|
||||
'settings.app_name' => 'required',
|
||||
'settings.app_domain' => 'required',
|
||||
'settings.app_timezone' => 'required',
|
||||
'settings.app_locale' => 'required',
|
||||
'settings.show_support' => 'boolean',
|
||||
]);
|
||||
|
||||
if ($v->passes()) {
|
||||
segment_track('Setup', [
|
||||
'event' => 'Step 1',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
return Response::json(['status' => 1]);
|
||||
} else {
|
||||
// No good, let's try that again.
|
||||
|
||||
segment_track('Setup', [
|
||||
'event' => 'Step 1',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Response::json(['errors' => $v->messages()], 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the actual app setup.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
|
||||
*/
|
||||
public function postStep2()
|
||||
{
|
||||
$postData = Binput::all();
|
||||
|
||||
segment_track('Setup', [
|
||||
'step' => '2',
|
||||
]);
|
||||
|
||||
$v = Validator::make($postData, [
|
||||
'settings.app_name' => 'required',
|
||||
'settings.app_domain' => 'required',
|
||||
'settings.app_timezone' => 'required',
|
||||
'settings.app_locale' => 'required',
|
||||
'settings.show_support' => 'boolean',
|
||||
'user.username' => 'alpha_num|required',
|
||||
'user.email' => 'email|required',
|
||||
'user.password' => 'required',
|
||||
]);
|
||||
|
||||
if ($v->passes()) {
|
||||
// Pull the user details out.
|
||||
$userDetails = array_pull($postData, 'user');
|
||||
|
||||
$user = User::create([
|
||||
'username' => $userDetails['username'],
|
||||
'email' => $userDetails['email'],
|
||||
'password' => $userDetails['password'],
|
||||
'level' => 1,
|
||||
]);
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
$settings = array_get($postData, 'settings');
|
||||
|
||||
foreach ($settings as $settingName => $settingValue) {
|
||||
Setting::create([
|
||||
'name' => $settingName,
|
||||
'value' => $settingValue,
|
||||
]);
|
||||
}
|
||||
|
||||
Session::flash('setup.done', true);
|
||||
|
||||
segment_track('Setup', [
|
||||
'event' => 'Step 2',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
if (Request::ajax()) {
|
||||
return Response::json(['status' => 1]);
|
||||
}
|
||||
|
||||
return Redirect::to('dashboard');
|
||||
} else {
|
||||
segment_track('Setup', [
|
||||
'event' => 'Step 2',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
// No good, let's try that again.
|
||||
if (Request::ajax()) {
|
||||
return Response::json(['errors' => $v->messages()], 400);
|
||||
}
|
||||
|
||||
return Redirect::back()->withInput()->with('errors', $v->messages());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user