admin) { throw new NoPermissionException(); } $apps = $appRepository->getAllApps(); return $response->withData(\App\Http\Resources\API\App::collection($apps)); } public function saveAppProperties(Request $request, Response $response, AppRepository $appRepository, $id) { if(!Auth::check()) { throw new NotLoggedInException(); } if(!Auth::user()->admin) { throw new NoPermissionException(); } $app = $appRepository->findById($id); $app->auto_accept = (bool)$request->input("autoAccept", false); $app->testing_warning = (bool)$request->input("testingWarning", false); $app->untrusted_warning = (bool)$request->input("untrustedWarning", false); $app->show_on_webpage = (bool)$request->input("showOnWebpage", false); $app->hidden_in_app_list = (bool)$request->input("hideInAppList", false); $app->user_cant_remove_app = (bool)$request->input("userCantRemoveApp", false); $app->stop_auto_redirect = (bool)$request->input("stopAutoRedirect", false); $appRepository->update($app); return $response; } public function listAllUsers(Request $request, Response $response) { // @todo replace with /api/v1/account call if(!Auth::check()) { abort(401); } if(!Auth::user()->admin) { throw new HTTPException("Need Admin Access"); } $user = User::all(); return $response->withData(\App\Http\Resources\API\User::collection($user)); } public function getUserDetails(Request $request, Response $response, $id) { // @todo replace with /api/v1/account/:id call if(!Auth::check()) { abort(401); } if(!Auth::user()->admin) { throw new HTTPException("Need Admin Access"); } $user = User::query()->where("id", "=", $id)->firstOrFail(); $mails = Mail::query()->where("user_id", "=", $id)->get(); $data = []; $data["details"] = new \App\Http\Resources\API\User($user); $data["mails"] = $mails; return $response->withData($data); } public function saveUserDetails(Request $request, Response $response, $id) { if(!Auth::user()->admin) { throw new HTTPException("Need Admin Access"); } $user = User::query()->where("id", "=", $id)->firstOrFail(); $user->admin = (bool)$request->input("admin", false); $user->developer = (bool)$request->input("developer", false); $user->username = $request->input("username"); $user->saveOrFail(); return $response; } public function resendValidationMail(Request $request, Response $response, $id) { if(!Auth::user()->admin) { throw new HTTPException("Need Admin Access"); } $mail = Mail::query()->where("id", "=", $id)->firstOrFail(); $this->dispatch(new ValidateMailAddressJob($mail)); $response->setStatusCode(201); return $response; } public function changeMailStatus(Request $request, Response $response, $id) { if(!Auth::user()->admin) { throw new HTTPException("Need Admin Access"); } $mail = Mail::query()->where("id", "=", $id)->firstOrFail(); $mail->status = $request->input("status"); if($mail->status == "valide") { $user = User::query()->where("id", "=", $mail->user_id)->firstOrFail(); if($user->getMail() == null) { $mail->primary = true; } } $mail->saveOrFail(); $response->setStatusCode(200); return $response; } public function listInvites(Request $request, Response $response) { if(!Auth::user()->admin) { throw new HTTPException("Need Admin Access"); } $invites = Invite::query()->get(); return $response->withData($invites); } public function inviteNew(Request $request, Response $response) { if(!Auth::user()->admin) { throw new HTTPException("Need Admin Access"); } $invite = new Invite(); $invite->user_id = Auth::user()->id; $invite->username = $request->input("username", null); $invite->comment = $request->input("comment", null); $invite->status = "active"; $invite->createToken(); $invite->saveOrFail(); return $response->withData($invite); } }