Add basic setup page. NoSetupFilter now prevents access too.
This commit is contained in:
@@ -2,6 +2,31 @@
|
||||
|
||||
class SetupController extends Controller {
|
||||
public function showSetup() {
|
||||
return View::make('setup');
|
||||
return View::make('setup')->with([
|
||||
'pageTitle' => 'Setup'
|
||||
]);
|
||||
}
|
||||
|
||||
public function setupCachet() {
|
||||
$postData = Input::get();
|
||||
$v = Validator::make($postData, [
|
||||
'app_name' => 'required',
|
||||
'app_domain' => 'url|required',
|
||||
'show_support' => 'boolean'
|
||||
]);
|
||||
|
||||
if ($v->passes()) {
|
||||
// Create the settings, boi.
|
||||
foreach ($postData as $settingName => $settingValue) {
|
||||
$setting = new Setting;
|
||||
$setting->name = $settingName;
|
||||
$setting->value = $settingValue;
|
||||
$setting->save();
|
||||
}
|
||||
return Redirect::to('/');
|
||||
} else {
|
||||
// No good, let's try that again.
|
||||
return Redirect::back()->with('errors', $v->messages());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
class NoSetupFilter {
|
||||
public function filter($route, $request, $settingName) {
|
||||
$setting = Setting::get($settingName);
|
||||
if ($setting === null) {
|
||||
return Response::make('Unauthorized', 401);
|
||||
try {
|
||||
$setting = Setting::where('name', $settingName)->first();
|
||||
if ($setting->value) {
|
||||
return Response::make('Unauthorized', 401);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,7 @@
|
||||
|
||||
Route::group(['before' => 'no_setup:app_name'], function() {
|
||||
Route::get('/setup', 'SetupController@showSetup');
|
||||
Route::group(['before' => 'csrf'], function() {
|
||||
Route::post('/setup', 'SetupController@setupCachet');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
<ul class='list-group components'>
|
||||
@foreach(Component::get() as $component)
|
||||
<li class='list-group-item component '>
|
||||
<!-- <span class='badge badge-{{ $component->color }}'><i class='glyphicon glyphicon-stop'></i></span> -->
|
||||
<h4>{{ $component->name }} <small class='{{ $component->color }}'>{{ $component->humanStatus }}</small></h4>
|
||||
<p>{{ $component->description }}</p>
|
||||
</li>
|
||||
@@ -18,4 +17,11 @@
|
||||
@for($i=0; $i <= 7; $i++)
|
||||
@include('incident', array('i', $i))
|
||||
@endfor
|
||||
|
||||
@if(Setting::get('show_support'))
|
||||
<hr />
|
||||
<div class='footer'>
|
||||
<p>{{ Setting::get('app_name') }} Status Page is powered by <a href='https://github.com/jbrooksuk/Cachet'>Cachet</a>.</p>
|
||||
</div>
|
||||
@endif
|
||||
@stop
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>{{ Setting::get('app_name') }} | Cachet</title>
|
||||
<title>{{ isset($pageTitle) ? $pageTitle : Setting::get('app_name') }} | Cachet</title>
|
||||
<!-- Set the viewport width to device width for mobile -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="author" content="http://james-brooks.uk">
|
||||
|
||||
@@ -1,15 +1,54 @@
|
||||
@extends('layout.master')
|
||||
|
||||
@section('content')
|
||||
<div class='page-header'>
|
||||
<ul class='list-group components'>
|
||||
@foreach(Component::get() as $component)
|
||||
<li class='list-group-item component '>
|
||||
<!-- <span class='badge badge-{{ $component->color }}'><i class='glyphicon glyphicon-stop'></i></span> -->
|
||||
<h4>{{ $component->name }} <small class='{{ $component->color }}'>{{ $component->humanStatus }}</small></h4>
|
||||
<p>{{ $component->description }}</p>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
<div class='jumbotron'>
|
||||
<h1>Setup Cachet</h1>
|
||||
<p class='lead'>Under construction.</p>
|
||||
</div>
|
||||
|
||||
<div class='row'>
|
||||
<div class='col-md-8'>
|
||||
<div class='panel panel-default'>
|
||||
<div class='panel-heading'>Service Details</div>
|
||||
<div class='panel-body'>
|
||||
<form name='SetupForm' class='form-vertical' role='form' method="POST">
|
||||
<div class='form-group'>
|
||||
<label class='sr-only'>Site Name</label>
|
||||
<input type='text' name='app_name' class='form-control' placeholder='Site Name' required />
|
||||
@if($errors->has('app_name'))
|
||||
<span class='text-danger'>{{ $errors->first('app_name') }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label class='sr-only'>Site Domain</label>
|
||||
<input type='text' name='app_domain' class='form-control' placeholder='Site Domain' required />
|
||||
@if($errors->has('app_domain'))
|
||||
<span class='text-danger'>{{ $errors->first('app_domain') }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<label>
|
||||
<input type='checkbox' name='show_support' value='1' checked />
|
||||
</label>
|
||||
Show support for Cachet?
|
||||
</div>
|
||||
<div class='form-group'>
|
||||
<button type='submit' class='btn btn-default'>Setup!</button>
|
||||
</div>
|
||||
{{ Form::token() }}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='col-md-4'>
|
||||
<div class='panel panel-info'>
|
||||
<div class='panel-heading'>Ding!</div>
|
||||
<div class='panel-body'>
|
||||
<p>You'll be able to reconfigure Cachet later on.</p>
|
||||
<p>At least when there is a management panel…</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@stop
|
||||
|
||||
Reference in New Issue
Block a user