63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Libraries\AuditLogger;
|
|
use App\Models\SettingsModel;
|
|
|
|
class SettingsController extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
$settings = new SettingsModel();
|
|
|
|
return view('admin/settings', [
|
|
'title' => 'Application settings | Chart-Board',
|
|
'allow_registration' => $settings->getBoolean(null, 'allow_registration', true),
|
|
'max_workspaces' => $settings->getInt(null, 'max_workspaces', 10),
|
|
]);
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
$rules = [
|
|
'allow_registration' => 'required|in_list[0,1]',
|
|
'max_workspaces' => 'required|integer|greater_than_equal_to[1]|less_than_equal_to[9999]',
|
|
];
|
|
|
|
if (! $this->validate($rules)) {
|
|
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
|
|
}
|
|
|
|
$settings = new SettingsModel();
|
|
$settings->setValue(
|
|
null,
|
|
'allow_registration',
|
|
(string) $this->request->getPost('allow_registration'),
|
|
'boolean'
|
|
);
|
|
$settings->setValue(
|
|
null,
|
|
'max_workspaces',
|
|
(string) $this->request->getPost('max_workspaces'),
|
|
'integer'
|
|
);
|
|
|
|
AuditLogger::log(
|
|
'app.settings_updated',
|
|
'settings',
|
|
null,
|
|
null,
|
|
[
|
|
'allow_registration' => (int) $this->request->getPost('allow_registration'),
|
|
'max_workspaces' => (int) $this->request->getPost('max_workspaces'),
|
|
],
|
|
null,
|
|
(int) $this->session->get('user_id')
|
|
);
|
|
|
|
return redirect()->to('/admin/settings')->with('success', 'Application settings updated.');
|
|
}
|
|
}
|