rbrecruiter/app/Http/Controllers/OptionsController.php

106 lines
3.6 KiB
PHP
Raw Permalink Normal View History

2020-08-30 22:06:01 +00:00
<?php
2020-10-10 16:30:26 +00:00
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
2020-08-30 22:06:01 +00:00
namespace App\Http\Controllers;
use App\Exceptions\InvalidGamePreferenceException;
use App\Exceptions\OptionNotFoundException;
2020-08-31 18:53:10 +00:00
use App\Facades\Options;
2020-08-31 16:55:36 +00:00
use App\Options as Option;
use App\Services\ConfigurationService;
2020-08-30 22:06:01 +00:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
2020-09-07 21:54:20 +00:00
use Illuminate\Support\Facades\Log;
2020-08-30 22:06:01 +00:00
class OptionsController extends Controller
{
private $configurationService;
public function __construct(ConfigurationService $configurationService) {
$this->configurationService = $configurationService;
}
2020-08-30 22:06:01 +00:00
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Http\Response|\Illuminate\View\View
*/
public function index()
{
// TODO: Replace with settings package
2020-08-31 16:58:07 +00:00
return view('dashboard.administration.settings')
->with([
'options' => Options::getCategory('notifications'),
'security' => [ // We could use the method above, but we need to set these names here for greater control in the template. This would nto be feasible for many options, we'd need to use a loop and the category method.
'secPolicy' => Options::getOption('pw_security_policy'),
'graceperiod' => Options::getOption('graceperiod'),
'pwExpiry' => Options::getOption('password_expiry'),
'requiresPMC' => Options::getOption('requireGameLicense'),
'enforce2fa' => Options::getOption('force2fa')
2021-01-06 01:55:22 +00:00
],
'currentGame' => Options::getOption('currentGame')
2021-01-06 00:57:27 +00:00
]);
2020-08-30 22:06:01 +00:00
}
public function saveSettings(Request $request): \Illuminate\Http\RedirectResponse
2020-10-10 16:30:26 +00:00
{
try {
if (Auth::user()->can('admin.settings.edit')) {
$this->configurationService->saveConfiguration($request->all());
2020-08-30 22:06:01 +00:00
return redirect()
->back()
->with('success', __('Options updated successfully!'));
2020-10-10 16:30:26 +00:00
}
} catch (OptionNotFoundException | \Exception $ex) {
return redirect()
->back()
->with('error', $ex->getMessage());
2020-10-10 16:30:26 +00:00
}
2020-08-30 22:06:01 +00:00
return redirect()
->back()
->with('error', __('You do not have permission to update this resource.'));
2020-10-10 16:30:26 +00:00
}
2021-01-06 01:55:22 +00:00
public function saveGameIntegration(Request $request)
{
try {
2021-01-06 01:55:22 +00:00
$this->configurationService->saveGameIntegration($request->gamePref);
return redirect()
->back()
->with('success', __('Game preference updated.'));
} catch (InvalidGamePreferenceException $ex) {
return redirect()
->back()
->with('error', $ex->getMessage());
}
2021-01-06 01:55:22 +00:00
}
2020-08-30 22:06:01 +00:00
}