Cachet/app/Http/Controllers/Admin/SettingsController.php

192 lines
5.7 KiB
PHP
Raw Normal View History

2014-12-20 21:20:17 +00:00
<?php
/*
* This file is part of Cachet.
*
* (c) James Brooks <james@cachethq.io>
* (c) Joseph Cohen <joseph.cohen@dinkbit.com>
* (c) Graham Campbell <graham@mineuk.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2015-03-20 18:30:45 -06:00
namespace CachetHQ\Cachet\Http\Controllers\Admin;
2015-01-01 15:45:04 +00:00
use CachetHQ\Cachet\Http\Controllers\AbstractController;
use CachetHQ\Cachet\Models\Setting;
2015-03-20 18:30:45 -06:00
use CachetHQ\Cachet\Models\User;
2015-01-01 15:45:04 +00:00
use Exception;
2015-01-02 12:05:50 +00:00
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Support\Facades\Lang;
2015-01-01 17:23:49 +00:00
use Illuminate\Support\Facades\Redirect;
2015-01-01 15:45:04 +00:00
use Illuminate\Support\Facades\View;
class SettingsController extends AbstractController
2014-12-20 21:20:17 +00:00
{
protected $subMenu = [];
protected $subTitle = 'Settings';
2014-12-31 11:39:28 +00:00
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,
2014-12-31 11:39:28 +00:00
],
];
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;
2015-01-01 10:39:22 +00:00
return View::make('dashboard.settings.app-setup')->with([
'pageTitle' => 'Application Setup - Dashboard',
2014-12-31 11:39:28 +00:00
'subMenu' => $this->subMenu,
]);
}
/**
* Shows the settings theme view.
*
* @return \Illuminate\View\View
*/
public function showThemeView()
{
$this->subMenu['theme']['active'] = true;
2015-01-01 10:39:22 +00:00
return View::make('dashboard.settings.theme')->with([
'pageTitle' => 'Theme - Dashboard',
2014-12-31 11:39:28 +00:00
'subMenu' => $this->subMenu,
]);
}
/**
* Shows the settings security view.
*
* @return \Illuminate\View\View
*/
public function showSecurityView()
{
$this->subMenu['security']['active'] = true;
2015-03-20 18:30:45 -06:00
$unsecureUsers = User::whereNull('google_2fa_secret')->orWhere('google_2fa_secret', '')->get();
2015-01-01 10:39:22 +00:00
return View::make('dashboard.settings.security')->with([
2015-03-20 18:30:45 -06:00
'pageTitle' => 'Security - Dashboard',
'subMenu' => $this->subMenu,
'unsecureUsers' => $unsecureUsers,
]);
}
2014-12-20 21:20:17 +00:00
/**
* Shows the settings stylesheet view.
2014-12-29 23:07:46 +00:00
*
2014-12-20 21:20:17 +00:00
* @return \Illuminate\View\View
*/
public function showStylesheetView()
2014-12-20 21:20:17 +00:00
{
$this->subMenu['stylesheet']['active'] = true;
2015-01-01 10:39:22 +00:00
return View::make('dashboard.settings.stylesheet')->with([
'pageTitle' => 'Stylesheet - Dashboard',
2014-12-31 11:39:28 +00:00
'subMenu' => $this->subMenu,
2014-12-20 21:20:17 +00:00
]);
}
2014-12-20 21:20:17 +00:00
/**
2014-12-31 11:45:54 +00:00
* Updates the status page settings.
2014-12-29 23:07:46 +00:00
*
2014-12-20 21:20:17 +00:00
* @return \Illuminate\View\View
*/
public function postSettings()
{
2015-01-04 12:25:21 +00:00
if (Binput::get('remove_banner') === '1') {
$setting = Setting::where('name', 'app_banner');
$setting->delete();
}
2015-01-02 12:05:50 +00:00
if (Binput::hasFile('app_banner')) {
$file = Binput::file('app_banner');
2014-12-31 11:45:54 +00:00
// Image Validation.
// Image size in bytes.
$maxSize = $file->getMaxFilesize();
2015-01-01 15:45:04 +00:00
2014-12-31 11:45:54 +00:00
if ($file->getSize() > $maxSize) {
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.too-big', [
'size' => $maxSize,
]));
2015-01-01 15:45:04 +00:00
}
if (!$file->isValid() || $file->getError()) {
return Redirect::back()->withErrors($file->getErrorMessage());
2015-01-01 15:45:04 +00:00
}
if (strpos($file->getMimeType(), 'image/') !== 0) {
return Redirect::back()->withErrors(trans('dashboard.settings.app-setup.images-only'));
2014-12-31 11:45:54 +00:00
}
// Store the banner.
Setting::firstOrCreate([
2014-12-31 11:51:06 +00:00
'name' => 'app_banner',
2014-12-31 11:45:54 +00:00
])->update([
2014-12-31 11:51:06 +00:00
'value' => base64_encode(file_get_contents($file->getRealPath())),
2014-12-31 11:45:54 +00:00
]);
// Store the banner type
Setting::firstOrCreate([
2014-12-31 11:51:06 +00:00
'name' => 'app_banner_type',
2014-12-31 11:45:54 +00:00
])->update([
2014-12-31 11:51:06 +00:00
'value' => $file->getMimeType(),
2014-12-31 11:45:54 +00:00
]);
}
try {
2015-01-02 12:05:50 +00:00
foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) {
2015-01-01 17:45:41 +00:00
Setting::firstOrCreate([
'name' => $settingName,
])->update([
'value' => $settingValue,
]);
}
} catch (Exception $e) {
return Redirect::back()->with('errors', trans('dashboard.settings.edit.failure'));
2014-12-20 21:20:17 +00:00
}
Lang::setLocale(Binput::get('app_locale'));
return Redirect::back()->with('success', trans('dashboard.settings.edit.success'));
2014-12-20 21:20:17 +00:00
}
}