2019-11-22 17:22:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
|
|
|
use App\Exceptions\HTTPException;
|
|
|
|
use App\Jobs\Mails\ValidateMailAddressJob;
|
2019-11-26 16:29:59 +00:00
|
|
|
use App\Models\App;
|
|
|
|
use App\Models\Invite;
|
2019-11-22 17:22:26 +00:00
|
|
|
use App\Models\Mail;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController;
|
|
|
|
use TaGeSo\APIResponse\Response;
|
|
|
|
|
|
|
|
class AdminController extends BaseController
|
|
|
|
{
|
|
|
|
|
2019-11-26 16:29:59 +00:00
|
|
|
public function listAllApps(Request $request, Response $response) {
|
|
|
|
if(!Auth::check()) {
|
|
|
|
abort(401);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!Auth::user()->admin) {
|
|
|
|
throw new HTTPException("Need Admin Access");
|
|
|
|
}
|
|
|
|
|
|
|
|
$apps = App::all();
|
|
|
|
|
|
|
|
|
|
|
|
return $response->withData(\App\Http\Resources\API\App::collection($apps));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function saveAppProperties(Request $request, Response $response, $id) {
|
|
|
|
if(!Auth::user()->admin) {
|
|
|
|
throw new HTTPException("Need Admin Access");
|
|
|
|
}
|
|
|
|
|
|
|
|
$app = App::query()->where("id", "=", $id)->first("*");
|
|
|
|
|
|
|
|
$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);
|
|
|
|
$app->saveOrFail();
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-22 17:22:26 +00:00
|
|
|
public function listAllUsers(Request $request, Response $response) {
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
2019-11-26 16:29:59 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2019-11-22 17:22:26 +00:00
|
|
|
}
|