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

273 lines
8.7 KiB
PHP
Raw Normal View History

2014-12-20 21:20:17 +00:00
<?php
/*
* This file is part of Cachet.
*
2015-07-06 17:37:01 +01:00
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
2015-01-01 15:45:04 +00:00
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\Routing\Controller;
2016-01-29 22:49:06 +00:00
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Lang;
2015-01-01 17:23:49 +00:00
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
2015-01-01 15:45:04 +00:00
use Illuminate\Support\Facades\View;
class SettingsController extends Controller
2014-12-20 21:20:17 +00:00
{
2015-11-04 15:02:56 +00:00
/**
* Array of sub-menu items.
*
* @var array
*/
protected $subMenu = [];
2015-11-04 15:02:56 +00:00
/**
* Creates a new settings controller instance.
*
* @return void
*/
2014-12-31 11:39:28 +00:00
public function __construct()
{
$this->subMenu = [
'setup' => [
'title' => trans('dashboard.settings.app-setup.app-setup'),
'url' => route('dashboard.settings.setup'),
'icon' => 'ion-gear-b',
'active' => false,
],
2015-11-12 00:22:40 +08:00
'theme' => [
'title' => trans('dashboard.settings.theme.theme'),
'url' => route('dashboard.settings.theme'),
'icon' => 'ion-paintbrush',
'active' => false,
],
'stylesheet' => [
'title' => trans('dashboard.settings.stylesheet.stylesheet'),
'url' => route('dashboard.settings.stylesheet'),
'icon' => 'ion-paintbucket',
'active' => false,
],
'customization' => [
'title' => trans('dashboard.settings.customization.customization'),
'url' => route('dashboard.settings.customization'),
'icon' => 'ion-wand',
'active' => false,
],
'localization' => [
'title' => trans('dashboard.settings.localization.localization'),
'url' => route('dashboard.settings.localization'),
'icon' => 'ion-earth',
'active' => false,
],
'security' => [
'title' => trans('dashboard.settings.security.security'),
'url' => route('dashboard.settings.security'),
'icon' => 'ion-lock-combination',
'active' => false,
],
2015-11-12 00:22:40 +08:00
'analytics' => [
'title' => trans('dashboard.settings.analytics.analytics'),
'url' => route('dashboard.settings.analytics'),
'icon' => 'ion-stats-bars',
'active' => false,
2014-12-31 11:39:28 +00:00
],
'about' => [
'title' => CACHET_VERSION,
'url' => 'javascript: void(0);',
'icon' => 'ion-flag',
'active' => false,
],
];
2015-11-04 15:02:56 +00:00
View::share([
'sub_title' => trans('dashboard.settings.settings'),
2015-11-04 15:02:56 +00:00
'sub_menu' => $this->subMenu,
]);
}
/**
* Shows the settings setup view.
*
* @return \Illuminate\View\View
*/
public function showSetupView()
{
$this->subMenu['setup']['active'] = true;
Session::flash('redirect_to', $this->subMenu['setup']['url']);
return View::make('dashboard.settings.app-setup')
->withPageTitle(trans('dashboard.settings.app-setup.app-setup').' - '.trans('dashboard.dashboard'))
->withSubMenu($this->subMenu)
2016-01-29 22:49:06 +00:00
->withRawAppAbout(Config::get('setting.app_about'));
}
/**
* Shows the settings analytics view.
*
* @return \Illuminate\View\View
*/
public function showAnalyticsView()
{
$this->subMenu['analytics']['active'] = true;
Session::flash('redirect_to', $this->subMenu['analytics']['url']);
return View::make('dashboard.settings.analytics')
->withPageTitle(trans('dashboard.settings.analytics.analytics').' - '.trans('dashboard.dashboard'))
->withSubMenu($this->subMenu);
}
/**
* Shows the settings localization view.
*
* @return \Illuminate\View\View
*/
public function showLocalizationView()
{
$this->subMenu['localization']['active'] = true;
Session::flash('redirect_to', $this->subMenu['localization']['url']);
return View::make('dashboard.settings.localization')
->withPageTitle(trans('dashboard.settings.localization.localization').' - '.trans('dashboard.dashboard'))
->withSubMenu($this->subMenu);
}
/**
* Shows the settings customization view.
*
* @return \Illuminate\View\View
*/
public function showCustomizationView()
{
$this->subMenu['customization']['active'] = true;
Session::flash('redirect_to', $this->subMenu['customization']['url']);
return View::make('dashboard.settings.customization')
->withPageTitle(trans('dashboard.settings.customization.customization').' - '.trans('dashboard.dashboard'))
->withSubMenu($this->subMenu);
}
/**
* Shows the settings theme view.
*
* @return \Illuminate\View\View
*/
public function showThemeView()
{
$this->subMenu['theme']['active'] = true;
Session::flash('redirect_to', $this->subMenu['theme']['url']);
return View::make('dashboard.settings.theme')
->withPageTitle(trans('dashboard.settings.theme.theme').' - '.trans('dashboard.dashboard'))
->withSubMenu($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();
Session::flash('redirect_to', $this->subMenu['security']['url']);
return View::make('dashboard.settings.security')
->withPageTitle(trans('dashboard.settings.security.security').' - '.trans('dashboard.dashboard'))
->withSubMenu($this->subMenu)
->withUnsecureUsers($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;
Session::flash('redirect_to', $this->subMenu['stylesheet']['url']);
return View::make('dashboard.settings.stylesheet')
->withPageTitle(trans('dashboard.settings.stylesheet.stylesheet').' - '.trans('dashboard.dashboard'))
->withSubMenu($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()
{
$redirectUrl = Session::get('redirect_to', route('dashboard.settings.setup'));
2016-01-29 22:49:06 +00:00
$setting = app('setting');
2015-01-04 12:25:21 +00:00
if (Binput::get('remove_banner') === '1') {
2016-01-29 22:49:06 +00:00
$setting->set('app_banner', null);
}
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::to($redirectUrl)->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::to($redirectUrl)->withErrors($file->getErrorMessage());
2015-01-01 15:45:04 +00:00
}
if (!starts_with($file->getMimeType(), 'image/')) {
return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.images-only'));
2014-12-31 11:45:54 +00:00
}
// Store the banner.
2016-01-29 22:49:06 +00:00
$setting->set('app_banner', base64_encode(file_get_contents($file->getRealPath())));
2014-12-31 11:45:54 +00:00
// Store the banner type.
2016-01-29 22:49:06 +00:00
$setting->set('app_banner_type', $file->getMimeType());
2014-12-31 11:45:54 +00:00
}
try {
foreach (Binput::except(['app_banner', 'remove_banner', '_token']) as $settingName => $settingValue) {
if ($settingName === 'app_analytics_pi_url') {
$settingValue = rtrim($settingValue, '/');
}
2016-01-29 22:49:06 +00:00
$setting->set($settingName, $settingValue);
}
} catch (Exception $e) {
return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.edit.failure'));
2014-12-20 21:20:17 +00:00
}
if (Binput::has('app_locale')) {
Lang::setLocale(Binput::get('app_locale'));
}
return Redirect::to($redirectUrl)->withSuccess(trans('dashboard.settings.edit.success'));
2014-12-20 21:20:17 +00:00
}
}