Access API
This commit is contained in:
parent
274d9e19b0
commit
5361185173
5 changed files with 48 additions and 4 deletions
|
@ -94,10 +94,10 @@ class UserController extends BaseController
|
||||||
$invite = Invite::query()->where("code", "=", $request->input("invite"))->first();
|
$invite = Invite::query()->where("code", "=", $request->input("invite"))->first();
|
||||||
if($invite != null) {
|
if($invite != null) {
|
||||||
if($invite->status != "active") {
|
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) {
|
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 {
|
} else {
|
||||||
|
|
|
@ -6,6 +6,7 @@ use App\Entity\Token;
|
||||||
use App\Exceptions\HTTPException;
|
use App\Exceptions\HTTPException;
|
||||||
use App\Exceptions\NotLoggedInException;
|
use App\Exceptions\NotLoggedInException;
|
||||||
use App\Exceptions\ResourceNotFound;
|
use App\Exceptions\ResourceNotFound;
|
||||||
|
use App\Http\Resources\API\AppAccessDetails;
|
||||||
use App\Models\AccessToken;
|
use App\Models\AccessToken;
|
||||||
use App\Models\App;
|
use App\Models\App;
|
||||||
use App\Models\AppAccess;
|
use App\Models\AppAccess;
|
||||||
|
@ -102,4 +103,19 @@ class oAuthController extends BaseController
|
||||||
|
|
||||||
return $response->withData($res);
|
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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -69,4 +69,4 @@ class AccessController extends Controller
|
||||||
|
|
||||||
return redirect("/gui/access");
|
return redirect("/gui/access");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
app/Http/Resources/API/AppAccessDetails.php
Normal file
25
app/Http/Resources/API/AppAccessDetails.php
Normal 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')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,6 +60,9 @@ $router->group(['prefix' => 'api'], function () use ($router) {
|
||||||
$router->post("/changeImage", ["uses" => "API\AppController@changeImage"]);
|
$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->group(['prefix' => 'account'], function () use ($router) {
|
||||||
$router->get("/", ['uses' => 'API\AccountController@getUsers']);
|
$router->get("/", ['uses' => 'API\AccountController@getUsers']);
|
||||||
$router->get("/{id}", ['uses' => 'API\AccountController@getUser']);
|
$router->get("/{id}", ['uses' => 'API\AccountController@getUser']);
|
||||||
|
|
Reference in a new issue