More Facades, User delete

This commit is contained in:
2024-07-22 00:56:04 +02:00
parent 4b89a7e9ca
commit 7b897071f5
14 changed files with 177 additions and 63 deletions
+4 -3
View File
@@ -6,6 +6,7 @@ use Exception;
use Pecee\Http\Middleware\IMiddleware;
use Pecee\Http\Request;
use Khofmann\Models\User\User;
use Khofmann\Response\Response;
class AdminAuth implements IMiddleware
{
@@ -15,17 +16,17 @@ class AdminAuth implements IMiddleware
// No token
if ($token === null) {
response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
}
try {
$user = User::getByToken($token);
if (!$user->getIsAdmin()) {
response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
}
} catch (Exception $err) {
// No user with this token exists
response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
}
}
}
+3 -2
View File
@@ -6,6 +6,7 @@ use Exception;
use Pecee\Http\Middleware\IMiddleware;
use Pecee\Http\Request;
use Khofmann\Models\User\User;
use Khofmann\Response\Response;
class Auth implements IMiddleware
{
@@ -15,14 +16,14 @@ class Auth implements IMiddleware
// No token
if ($token === null) {
response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
}
try {
User::getByToken($token);
} catch (Exception $err) {
// No user with this token exists
response()->httpCode(401)->json(["message" => "Not Authorized"]);
Response::response()->httpCode(401)->json(["message" => "Not Authorized"]);
}
}
}