Stuff i guess ?

This commit is contained in:
Lars Behrends
2025-10-31 00:24:17 +01:00
parent db0fd4e728
commit 04140786a7
40 changed files with 5411 additions and 525 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Controllers\Api;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use App\Controllers\Controller;
use App\Services\AuthService;
class AuthController extends Controller
{
private AuthService $authService;
public function __construct(AuthService $authService)
{
$this->authService = $authService;
}
/**
* Check if user is authenticated (API endpoint)
*/
public function checkAuth(Request $request, Response $response, $args)
{
try {
if (!$this->authService->isLoggedIn()) {
return $this->jsonResponse($response->withStatus(401), [
'error' => '401 Forbidden'
]);
}
$user = $this->authService->getCurrentUser();
if (!$user) {
return $this->jsonResponse($response->withStatus(401), [
'error' => '401 Forbidden'
]);
}
return $this->jsonResponse($response, [
'id' => $user['id'],
'username' => $user['username'],
'email' => $user['email'],
'is_admin' => $this->authService->isAdmin()
]);
} catch (\Exception $e) {
return $this->jsonResponse($response->withStatus(500), [
'error' => 'Authentication check failed'
]);
}
}
}