Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // 4o
- /**
- * @file AuthController.php
- * @description Handles HTTP requests for authentication. It processes user input,
- * manages CSRF tokens, and interacts with the AuthService to perform
- * the actual login logic. It is responsible for redirects and rendering views.
- *
- * @version 1.0.0
- * @since 2025-07-25
- * @author Barrac0de
- */
- namespace App\Controllers;
- use App\Services\AuthService;
- class AuthController
- {
- public static function handle(): void
- {
- session_start();
- if ($_SERVER['REQUEST_METHOD'] === 'GET') {
- if (isset($_SESSION['user_id'])) {
- header('Location: ' . BASE_PATH . 'index');
- exit;
- }
- $error = $_SESSION['login_error'] ?? '';
- $oldUsername = $_SESSION['old_username'] ?? '';
- unset($_SESSION['login_error'], $_SESSION['old_username']);
- if (empty($_SESSION['csrf_token'])) {
- $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
- }
- require __DIR__ . '/../../login.php';
- exit;
- }
- // POST request
- $auth = new AuthService();
- $auth->processLogin();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment