This commit is contained in:
2026-04-02 16:33:32 +02:00
parent 72108d4d03
commit e79cc73e6d
17 changed files with 720 additions and 23 deletions

View File

@@ -6,6 +6,7 @@ use App\Domain\Controller;
use App\Helpers\Authentification;
use App\Http\JSONResponse;
use App\Http\Request;
use App\Infrastructure\View;
class AuthentificationController extends Controller {
@@ -15,19 +16,29 @@ class AuthentificationController extends Controller {
// Public routes.
self::Route( routeUrl: '/login', routeName: 'login', routeAction: 'loginForm', pageHeadTitle: 'Connexion' ),
self::Route( routeUrl: '/logout', routeName: 'logout', routeAction: 'logoutPage', pageHeadTitle: 'Déconnexion' ),
// API Routes.
self::Route( routeUrl: '/api/auth', routeName: 'api->auth', routeAction: 'auth', routeMethods: ['POST'] ),
self::Route( routeUrl: '/api/auth/logout', routeName: 'api->auth->logout', routeAction: 'logout', routeMethods: ['POST'] ),
// self::Route( routeUrl: '/api/auth/logout', routeName: 'api->auth->logout', routeAction: 'logout', routeMethods: ['POST'] ),
];
}
public function login(): View {
public function loginForm(): View {
return new View( 'login' );
}
public function logoutPage(){
if( !Authentification::isLoggedIn() ) {
Request::redirectTo( 'home' );
}
Authentification::destroySession();
Request::redirectTo( 'home' );
}
public function auth(): JSONResponse {
Request::setCORS();
@@ -39,14 +50,14 @@ class AuthentificationController extends Controller {
$userId = 1;
Authentification::loginUser( $userId );
JSONResponse::sendSuccess( [ 'user_id' => $userId ] );
return JSONResponse::sendSuccess( [ 'user_id' => $userId ] );
}
public function logout(): JSONResponse {
if( !Authentification::isLoggedIn() ) {
return JSONResponse::sendError( [ 'message' => 'Alrady disconnected' ] );
return JSONResponse::sendError( [ 'message' => 'Already disconnected' ] );
}
Authentification::destroySession();