Documentation

AuthManager
in package

AuthManager - Authentication and Authorization Management

Replaces procedural functions from app/include/auth.php Manages authentication state in an object-oriented manner.

SRP (Single Responsibility Principle): This class ONLY manages authentication state. It does NOT handle HTTP redirections (that's the Application/Router role).

Features:

  • User login/logout
  • Authentication checks
  • Authorization checks (admin vs regular user)
  • Session regeneration for security
  • User data retrieval
Tags
author

BDELIVE - Groupe 8

version
1.6.0

Table of Contents

Constants

USER_EMAIL_KEY  = 'user_email'
USER_FIRST_NAME_KEY  = 'user_first_name'
USER_ID_KEY  = 'user_id'
USER_LAST_NAME_KEY  = 'user_last_name'
USER_STATUS_KEY  = 'user_status'

Properties

$session  : SessionManager

Methods

__construct()  : mixed
getUser()  : array<string, mixed>|null
Get all user data as an array
getUserEmail()  : string|null
Get the user's email address
getUserFirstName()  : string|null
Get the user's first name
getUserId()  : int|null
Get the authenticated user's ID
getUserLastName()  : string|null
Get the user's last name
getUserRole()  : string
Get the current user's role
getUserStatus()  : string|null
Get the user's status
isAdmin()  : bool
Check if the user is an administrator (admin or super_admin)
isAuthenticated()  : bool
Check if user is authenticated
isBlocked()  : bool
Check if user is blocked
isSuperAdmin()  : bool
Check if the user is a super administrator
login()  : void
Log in a user
logout()  : void
Log out the current user
requireAdmin()  : void
Require user to be an administrator (BDE)
requireAuthentication()  : void
Require user to be authenticated

Constants

USER_EMAIL_KEY

private mixed USER_EMAIL_KEY = 'user_email'

USER_FIRST_NAME_KEY

private mixed USER_FIRST_NAME_KEY = 'user_first_name'

USER_LAST_NAME_KEY

private mixed USER_LAST_NAME_KEY = 'user_last_name'

USER_STATUS_KEY

private mixed USER_STATUS_KEY = 'user_status'

Properties

Methods

getUser()

Get all user data as an array

public getUser() : array<string, mixed>|null

Returns a complete array of user information suitable for passing to views. Returns null if user is not authenticated.

Return values
array<string, mixed>|null

User data array or null if not authenticated

getUserEmail()

Get the user's email address

public getUserEmail() : string|null
Return values
string|null

Email or null if not authenticated

getUserFirstName()

Get the user's first name

public getUserFirstName() : string|null
Return values
string|null

First name or null if not set/authenticated

getUserId()

Get the authenticated user's ID

public getUserId() : int|null
Return values
int|null

User ID or null if not authenticated

getUserLastName()

Get the user's last name

public getUserLastName() : string|null
Return values
string|null

Last name or null if not set/authenticated

getUserRole()

Get the current user's role

public getUserRole() : string
Return values
string

The role ('user', 'admin', or 'super_admin')

getUserStatus()

Get the user's status

public getUserStatus() : string|null

Possible values: BUT 1, BUT 2, BUT 3, Personnel Enseignant, BDE

Return values
string|null

User status or null if not authenticated

isAdmin()

Check if the user is an administrator (admin or super_admin)

public isAdmin() : bool
Return values
bool

True if user has admin rights and not blocked

isAuthenticated()

Check if user is authenticated

public isAuthenticated() : bool
Return values
bool

True if user is logged in

isBlocked()

Check if user is blocked

public isBlocked() : bool
Return values
bool

True if user is blocked

isSuperAdmin()

Check if the user is a super administrator

public isSuperAdmin() : bool
Return values
bool

True if user has super_admin role and not blocked

login()

Log in a user

public login(int $userId, string $userStatus, string $email[, string $role = 'user' ][, int $isBlocked = 0 ][, string $firstName = '' ][, string $lastName = '' ]) : void

Stores user information in session and regenerates session ID to prevent session fixation attacks.

Parameters
$userId : int

User ID from database

$userStatus : string

User status (BUT 1, BUT 2, BUT 3, Personnel Enseignant, BDE)

$email : string

User email address

$role : string = 'user'
$isBlocked : int = 0
$firstName : string = ''

User first name (optional)

$lastName : string = ''

User last name (optional)

logout()

Log out the current user

public logout() : void

Removes all user data from session. Session itself remains active.

requireAdmin()

Require user to be an administrator (BDE)

public requireAdmin() : void

Throws an exception if user doesn't have admin rights. Redirect handling is delegated to the Application/Router layer.

Tags
throws
AuthenticationException

If user is not logged in

throws
AuthorizationException

If user is not an admin

requireAuthentication()

Require user to be authenticated

public requireAuthentication() : void

Throws an exception if user is not logged in. Redirect handling is delegated to the Application/Router layer.

Tags
throws
AuthenticationException

If user is not authenticated


        
On this page

Search results