2019-05-22 12:44:51 +00:00
|
|
|
<?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;
|
2019-07-18 08:18:08 +00:00
|
|
|
use Illuminate\Http\Request;
|
2019-05-22 12:44:51 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController;
|
|
|
|
use TaGeSo\APIResponse\Response;
|
|
|
|
|
|
|
|
class ServerController extends BaseController
|
|
|
|
{
|
2019-07-18 08:18:08 +00:00
|
|
|
public function getSettings(Request $request,Response $response) {
|
2019-05-22 12:44:51 +00:00
|
|
|
$settings = Setting::getPublicSettings();
|
|
|
|
|
2019-07-18 08:18:08 +00:00
|
|
|
if($request->input("all") == true) {
|
|
|
|
if(!Auth::check()) {
|
|
|
|
throw new NotLoggedInException();
|
|
|
|
}
|
|
|
|
if(!Auth::user()->admin) {
|
|
|
|
throw new NoPermissionException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$settings = Setting::all();
|
|
|
|
}
|
2019-05-22 12:44:51 +00:00
|
|
|
return $response->withData(\App\Http\Resources\API\Setting::collection(collect($settings)));
|
|
|
|
}
|
2019-11-22 15:13:42 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2019-05-22 12:44:51 +00:00
|
|
|
}
|