60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Exceptions\HTTPException;
|
|
use App\Exceptions\NoPermissionException;
|
|
use App\Exceptions\NotLoggedInException;
|
|
use App\Exceptions\ResourceNotFound;
|
|
use App\Models\Setting;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Laravel\Lumen\Routing\Controller as BaseController;
|
|
use TaGeSo\APIResponse\Response;
|
|
|
|
class ServerController extends BaseController
|
|
{
|
|
public function getSettings(Request $request,Response $response) {
|
|
$settings = Setting::getPublicSettings();
|
|
|
|
if($request->input("all") == true) {
|
|
if(!Auth::check()) {
|
|
throw new NotLoggedInException();
|
|
}
|
|
if(!Auth::user()->admin) {
|
|
throw new NoPermissionException();
|
|
}
|
|
|
|
$settings = Setting::all();
|
|
}
|
|
return $response->withData(\App\Http\Resources\API\Setting::collection(collect($settings)));
|
|
}
|
|
|
|
public function saveSettings(Request $request, Response $response) {
|
|
if(!Auth::user()->admin) {
|
|
throw new HTTPException("Need Admin Access");
|
|
}
|
|
$settings = Setting::query()->get("*");
|
|
|
|
foreach($settings as $setting) {
|
|
switch ($setting->typ) {
|
|
case "checkbox":
|
|
if($request->input($setting->name, false)) {
|
|
$setting->value = true;
|
|
} else {
|
|
$setting->value = false;
|
|
}
|
|
$setting->saveOrFail();
|
|
case "textinput":
|
|
$setting->value = $request->input($setting->name, "");
|
|
$setting->saveOrFail();
|
|
case "password":
|
|
$setting->value = $request->input($setting->name, "");
|
|
$setting->saveOrFail();
|
|
}
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
}
|