Access API

This commit is contained in:
Kekskurse 2019-09-25 09:56:36 +02:00
parent 274d9e19b0
commit 5361185173
5 changed files with 48 additions and 4 deletions

View file

@ -94,10 +94,10 @@ class UserController extends BaseController
$invite = Invite::query()->where("code", "=", $request->input("invite"))->first();
if($invite != null) {
if($invite->status != "active") {
throw new HTTPException("Invite code invalide");
throw new HTTPException(400, "Invite code invalide");
}
if(!empty($invite->username) && $request->input("username") != $invite->username) {
throw new HTTPException("Invalide username for invite");
throw new HTTPException(400, "Invalide username for invite");
}
} else {

View file

@ -6,6 +6,7 @@ use App\Entity\Token;
use App\Exceptions\HTTPException;
use App\Exceptions\NotLoggedInException;
use App\Exceptions\ResourceNotFound;
use App\Http\Resources\API\AppAccessDetails;
use App\Models\AccessToken;
use App\Models\App;
use App\Models\AppAccess;
@ -102,4 +103,19 @@ class oAuthController extends BaseController
return $response->withData($res);
}
}
public function listAccess(Response $response) {
if(!Auth::check()) {
abort(401);
}
$access = AppAccess::query()->where("user_id", "=", Auth::user()->id)->get();
$visibleAccess = [];
foreach($access as $a) {
if(!$a->getApp()->hidden_in_app_list) {
$visibleAccess[] = $a;
}
}
return $response->withData(AppAccessDetails::collection(collect($visibleAccess)));
}
}

View file

@ -69,4 +69,4 @@ class AccessController extends Controller
return redirect("/gui/access");
}
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources\API;
use Illuminate\Http\Resources\Json\JsonResource;
class AppAccessDetails extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$app = $this->getApp();
return [
'app' => new App($app),
'status' => $this->status,
'created' => $this->created_at->format('Y-m-d H:i:s e'),
'updated' => $this->created_at->format('Y-m-d H:i:s e')
];
}
}

View file

@ -60,6 +60,9 @@ $router->group(['prefix' => 'api'], function () use ($router) {
$router->post("/changeImage", ["uses" => "API\AppController@changeImage"]);
});
});
$router->group(["prefix" => "access"], function () use ($router) {
$router->get("", ["uses" => "API\oAuthController@listAccess"]);
});
$router->group(['prefix' => 'account'], function () use ($router) {
$router->get("/", ['uses' => 'API\AccountController@getUsers']);
$router->get("/{id}", ['uses' => 'API\AccountController@getUser']);