Added services
This commit moves most controller logic onto Services. Services are part of the Service-Repository pattern. The models act as repositories. Services are easily testable and are needed for the upcoming API, in order to avoid duplicated code and to maintain a single source of "truth". The User, Vacancy and Vote controllers still need their logic moved onto services.
This commit is contained in:
54
app/Services/SecuritySettingsService.php
Normal file
54
app/Services/SecuritySettingsService.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Facades\Options;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SecuritySettingsService
|
||||
{
|
||||
|
||||
/**
|
||||
* Saves the app security settings.
|
||||
*
|
||||
* @param $policy
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
public function save($policy, $options = []) {
|
||||
|
||||
$validPolicies = [
|
||||
'off',
|
||||
'low',
|
||||
'medium',
|
||||
'high'
|
||||
];
|
||||
|
||||
if (in_array($policy, $validPolicies))
|
||||
{
|
||||
Options::changeOption('pw_security_policy', $policy);
|
||||
|
||||
Log::debug('[Options] Changing option pw_security_policy', [
|
||||
'new_value' => $policy
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::debug('[WARN] Ignoring bogus policy', [
|
||||
'avaliable' => $validPolicies,
|
||||
'given' => $policy
|
||||
]);
|
||||
}
|
||||
|
||||
Options::changeOption('graceperiod', $options['graceperiod']);
|
||||
Options::changeOption('password_expiry', $options['pwexpiry']);
|
||||
Options::changeOption('force2fa', $options['enforce2fa']);
|
||||
Options::changeOption('requireGameLicense', $options['requirePMC']);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user