Settings for Admin

This commit is contained in:
Kekskurse 2019-07-18 10:18:08 +02:00
parent 2076182bd6
commit 7926010a26
2 changed files with 14 additions and 2 deletions

View file

@ -3,7 +3,7 @@ namespace App\Exceptions;
class NoPermissionException extends HTTPException class NoPermissionException extends HTTPException
{ {
public function __construct($httpCode = 403, $message = "You need to login", $code = 0, Exception $previous = null) { public function __construct($httpCode = 403, $message = "You don't have the permission for this call", $code = 0, Exception $previous = null) {
parent::__construct($httpCode, $message, $code, $previous); parent::__construct($httpCode, $message, $code, $previous);
} }
} }

View file

@ -8,15 +8,27 @@ use App\Exceptions\NotLoggedInException;
use App\Exceptions\ResourceNotFound; use App\Exceptions\ResourceNotFound;
use App\Models\Setting; use App\Models\Setting;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
use TaGeSo\APIResponse\Response; use TaGeSo\APIResponse\Response;
class ServerController extends BaseController class ServerController extends BaseController
{ {
public function getSettings(Response $response) { public function getSettings(Request $request,Response $response) {
$settings = Setting::getPublicSettings(); $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))); return $response->withData(\App\Http\Resources\API\Setting::collection(collect($settings)));
} }
} }