Documentation

API Documentation

Table of Contents

Namespaces

App

Constants

CSP_NONCE  = $cspNonce
DB_CHARSET  = $_ENV['DB_CHARSET'] ?? $_SERVER['DB_CHARSET'] ?? 'utf8mb4'
DB_HOST  = $_ENV['DB_HOST'] ?? $_SERVER['DB_HOST'] ?? '127.0.0.1'
DB_NAME  = $_ENV['DB_NAME'] ?? $_SERVER['DB_NAME'] ?? 'bdelive_test'
DB_PASSWORD  = $_ENV['DB_PASSWORD'] ?? $_SERVER['DB_PASSWORD'] ?? 'root'
DB_USER  = $_ENV['DB_USER'] ?? $_SERVER['DB_USER'] ?? 'root'
FROM_EMAIL  = (string) $_ENV['FROM_EMAIL']

Functions

requireLogin()  : void
Require user authentication
requireAdmin()  : void
Require events privileges
generateCsrfToken()  : string
Generate a CSRF token and store it in session
validateCsrfToken()  : bool
Validate CSRF token
csrfField()  : string
Get CSRF token field HTML
csrfField()  : string
Generate a CSRF token hidden input field
validateCsrfToken()  : bool
Validate a CSRF token
generateCsrfToken()  : string
Generate a new CSRF token
requireLogin()  : void
Require user authentication
requireAdmin()  : void
Require administrator rights (BDE)
useCarousel()  : void
Carousel Component
start_page()  : void
Renders the page header with navigation
end_page()  : void
Renders the page footer

Constants

CSP_NONCE

public mixed CSP_NONCE = $cspNonce

DB_CHARSET

public mixed DB_CHARSET = $_ENV['DB_CHARSET'] ?? $_SERVER['DB_CHARSET'] ?? 'utf8mb4'

DB_HOST

public mixed DB_HOST = $_ENV['DB_HOST'] ?? $_SERVER['DB_HOST'] ?? '127.0.0.1'

DB_NAME

public mixed DB_NAME = $_ENV['DB_NAME'] ?? $_SERVER['DB_NAME'] ?? 'bdelive_test'

DB_PASSWORD

public mixed DB_PASSWORD = $_ENV['DB_PASSWORD'] ?? $_SERVER['DB_PASSWORD'] ?? 'root'

DB_USER

public mixed DB_USER = $_ENV['DB_USER'] ?? $_SERVER['DB_USER'] ?? 'root'

FROM_EMAIL

public mixed FROM_EMAIL = (string) $_ENV['FROM_EMAIL']

Functions

requireLogin()

Require user authentication

requireLogin() : void

Checks if a user session is active and if the user is logged in. Redirects to the login page with an error message if the user is not authenticated.

Tags
author

BDELIVE - Groupe 8

throws
void

Exits execution if user is not authenticated

requireAdmin()

Require events privileges

requireAdmin() : void

Checks if a user session is active, if the user is logged in, and if the user has events status ('BDE'). Redirects to login page if not authenticated, or returns 403 Forbidden if authenticated but not events.

Tags
throws
void

Exits execution if user is not authenticated or not events

generateCsrfToken()

Generate a CSRF token and store it in session

generateCsrfToken() : string

Generates a cryptographically secure random token (64 hex characters) and stores it in the session along with a timestamp.

Return values
string

The generated token (64 hex characters), or empty string if session is not active

validateCsrfToken()

Validate CSRF token

validateCsrfToken(string $token) : bool

Validates that the provided token matches the token stored in the session and that the token has not expired (1 hour expiration).

Parameters
$token : string

The token to validate

Return values
bool

True if the token is valid and not expired, false otherwise

csrfField()

Get CSRF token field HTML

csrfField() : string

Generates an HTML hidden input field containing the CSRF token. Uses an existing token if available, otherwise generates a new one.

Return values
string

HTML input field with CSRF token, or empty string if session is not active

csrfField()

Generate a CSRF token hidden input field

csrfField() : string

Convenience function that wraps CsrfProtection::getTokenField().

Tags
see
CsrfProtection::getTokenField()
example

// Or use OOP approach in views:

getTokenField() ?>
Return values
string

HTML hidden input with CSRF token

validateCsrfToken()

Validate a CSRF token

validateCsrfToken(string $token) : bool

Convenience function that wraps CsrfProtection::validateToken().

Parameters
$token : string

The CSRF token to validate

Tags
see
CsrfProtection::validateToken()
example

if (validateCsrfToken($_POST['csrf_token'])) { // Token is valid }

// Or use OOP approach in controllers: if ($this->csrf->validateToken($token)) { ... }

Return values
bool

True if valid, false otherwise

generateCsrfToken()

Generate a new CSRF token

generateCsrfToken() : string

Convenience function that wraps CsrfProtection::generateToken().

Tags
see
CsrfProtection::generateToken()
example

$token = generateCsrfToken();

// Or use OOP approach in controllers: $token = $this->csrf->generateToken();

Return values
string

The generated CSRF token (64 hex characters)

requireLogin()

Require user authentication

requireLogin() : void

Checks if user is authenticated and redirects to login page if not. Convenience function that wraps AuthManager::requireAuthentication().

Tags
see
AuthManager::requireAuthentication()
see
AuthenticatedController

For OOP approach

example

// In procedural code: requireLogin();

// Or use OOP approach - extend AuthenticatedController: class MyController extends AuthenticatedController { // Authentication checked automatically in constructor }

Return values
void

Redirects to login page if not authenticated

requireAdmin()

Require administrator rights (BDE)

requireAdmin() : void

Checks if user is authenticated and has admin (BDE) status. Redirects to login or home page with error message if requirements not met. Convenience function that wraps AuthManager::requireAdmin().

Tags
see
AuthManager::requireAdmin()
see
AdminController

For OOP approach

example

// In procedural code: requireAdmin();

// Or use OOP approach - extend AdminController: class MyAdminController extends AdminController { // Admin rights checked automatically in constructor }

Return values
void

Redirects if not authenticated or not admin

useCarousel()

Carousel Component

useCarousel(string $carouselLabel, array<int, array{src: string, alt?: string}> $imageMap, string $carouselId, mixed $event) : void

Reusable carousel component for displaying sliding image content. Used on homepage and other pages for featured content display.

Parameters
$carouselLabel : string
$imageMap : array<int, array{src: string, alt?: string}>
$carouselId : string
$event : mixed
Tags
version
1.0.0
author

BdeLive - Group 8

start_page()

Renders the page header with navigation

start_page(string $title[, bool $wouldNav = true ][, array<string, mixed>|null $user = null ]) : void

Generates the HTML head section and navigation bar with responsive hamburger menu for mobile devices. Includes user-specific navigation options based on authentication status and user role.

Parameters
$title : string

Page title for the browser tab

$wouldNav : bool = true

Whether to display the navigation bar

$user : array<string, mixed>|null = null

Current user data or null if not logged in

Tags
author

BdeLive Team

version
1.1.0

end_page()

Renders the page footer

end_page() : void

Generates the HTML footer section with navigation links, social media icons, and copyright information. Also handles cookie consent popup display.

Tags
author

BdeLive Team

version
1.1.0

        
On this page

Search results