diff --git a/app/Exceptions/NoPermissionException.php b/app/Exceptions/NoPermissionException.php index e7ee7c9..31d2f87 100644 --- a/app/Exceptions/NoPermissionException.php +++ b/app/Exceptions/NoPermissionException.php @@ -3,7 +3,7 @@ namespace App\Exceptions; 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); } } \ No newline at end of file diff --git a/app/Http/Controllers/API/ServerController.php b/app/Http/Controllers/API/ServerController.php index 792b27e..0913881 100644 --- a/app/Http/Controllers/API/ServerController.php +++ b/app/Http/Controllers/API/ServerController.php @@ -8,15 +8,27 @@ 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(Response $response) { + 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))); } }