HelPHP

User
in package

Tags
class

User

Handles user management, authentication, and session state for the application. Provides methods for account creation, activation, login, logout, group and module access control, error/message handling, and connection/session management.

This class manage the $USER global object and most of its methods can be used by the User module.

Table of Contents

Constants

action_identifier  = 'user_action'
activate  = 'activate'
connect  = 'connect'
create  = 'create'
disconnect  = 'disconnect'
session_connection_data  = 'connection_data'
session_connection_state  = 'connection_state'
session_try_identifier  = 'connection_try'
session_user_id  = 'id'
session_user_login  = 'login'
state_ban  = -1
state_logged  = 1
state_not_logged  = 0

Properties

$account_created  : bool|null
$admin  : bool
$connection_hash  : string|null
$connection_state  : int
$error_list  : array<string|int, mixed>
$force_reload_delay  : int
$id  : int
$id_activated  : int
$login  : string
$message_list  : array<string|int, mixed>
$nb_attempt  : int
$reload_after_message  : bool
$user_data  : mixed

Methods

__construct()  : mixed
account_exists()  : array<string|int, mixed>
Checks if an account exists for the given login and email.
allowed_admin_modules()  : array<string|int, mixed>
Returns the list of admin modules accessible for the user's group(s).
allowed_groups()  : array<string|int, mixed>
Returns the list of group IDs the user is allowed to access.
allowed_public_modules()  : array<string|int, mixed>
Returns the list of public modules accessible to any user.
allowed_registered_modules()  : array<string|int, mixed>
Returns the list of registered modules accessible for the user's group(s).
check_connection()  : void
Checks the current user connection/session and updates user state.
check_connection_data()  : int
Handles user connection actions (create, activate, connect, disconnect) based on provided data.
create_account()  : bool
Creates a new user account.
create_instance()  : void
Creates the global instance $USER of the User class.
email_exists()  : bool
Checks if a email already exists.
generate_activation_code()  : string|true|null
Generates an activation code for the user account.
get_connection_duration()  : int
Returns the duration (in seconds) of the current connection.
get_error_list()  : array<string|int, mixed>
Returns the current error list.
get_message_list()  : array<string|int, mixed>
Returns the current message list.
get_user_agent()  : string
Returns the current user agent string.
login_exists()  : bool
Checks if a login already exists.
reset()  : void
Resets the user session and connection state.
restricted_edit_modules()  : array<string|int, mixed>
Returns the list of modules with restricted editing for the user's group(s).

Constants

action_identifier

public mixed action_identifier = 'user_action'

activate

public mixed activate = 'activate'

connect

public mixed connect = 'connect'

create

public mixed create = 'create'

disconnect

public mixed disconnect = 'disconnect'

session_connection_data

public mixed session_connection_data = 'connection_data'

session_connection_state

public mixed session_connection_state = 'connection_state'

session_try_identifier

public mixed session_try_identifier = 'connection_try'

session_user_id

public mixed session_user_id = 'id'

session_user_login

public mixed session_user_login = 'login'

state_ban

public mixed state_ban = -1

state_logged

public mixed state_logged = 1

state_not_logged

public mixed state_not_logged = 0

Properties

$account_created

public bool|null $account_created = null

Whether the account was successfully created.

$admin

public bool $admin = false

Whether the user has admin privileges.

$connection_hash

public string|null $connection_hash = null

The hash identifying the user's session.

$connection_state

public int $connection_state

The user's connection state (banned, not logged, logged).

$error_list

public array<string|int, mixed> $error_list = []

List of error messages displayed in popups.

$force_reload_delay

public int $force_reload_delay = 0

Delay before forcing reload after message.

$id

public int $id = 0

The user's unique ID.

$id_activated

public int $id_activated = 0

ID of the activated user.

$login

public string $login = ''

The user's login name.

$message_list

public array<string|int, mixed> $message_list = []

List of informative messages displayed in popups.

$nb_attempt

public int $nb_attempt = 0

Number of connection attempts.

$reload_after_message

public bool $reload_after_message = false

If true, the page will be reloaded when the popup is closed.

$user_data

public mixed $user_data = 0

User data array or object. will be used to store details.

Methods

__construct()

public __construct() : mixed

account_exists()

Checks if an account exists for the given login and email.

public account_exists(string $login, string $email) : array<string|int, mixed>
Parameters
$login : string
$email : string
Return values
array<string|int, mixed>

Array with 'login' and 'email' keys if found.

allowed_admin_modules()

Returns the list of admin modules accessible for the user's group(s).

public allowed_admin_modules([int $id = 0 ]) : array<string|int, mixed>
Parameters
$id : int = 0

Optional. User ID to check (defaults to current user).

Return values
array<string|int, mixed>

List of admin module names.

allowed_groups()

Returns the list of group IDs the user is allowed to access.

public allowed_groups([int $id = 0 ]) : array<string|int, mixed>
Parameters
$id : int = 0

Optional. User ID to check (defaults to current user).

Return values
array<string|int, mixed>

List of group IDs.

allowed_public_modules()

Returns the list of public modules accessible to any user.

public allowed_public_modules() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of public module names.

allowed_registered_modules()

Returns the list of registered modules accessible for the user's group(s).

public allowed_registered_modules([int $id = 0 ]) : array<string|int, mixed>
Parameters
$id : int = 0

Optional. User ID to check (defaults to current user).

Return values
array<string|int, mixed>

List of registered module names.

check_connection()

Checks the current user connection/session and updates user state.

public check_connection([string|false $connection_hash = false ]) : void

and will ban the navigatorby its user-agent after 5 tries.

Parameters
$connection_hash : string|false = false

Optional.

check_connection_data()

Handles user connection actions (create, activate, connect, disconnect) based on provided data.

public check_connection_data([array<string|int, mixed>|null $connection_data = null ]) : int
Parameters
$connection_data : array<string|int, mixed>|null = null

Connection data (from POST/REQUEST).

Return values
int

The user's connection state.

create_account()

Creates a new user account.

public create_account(array<string|int, mixed> $data) : bool

Validates login, email, password, and VAT ID, checks for duplicates, and inserts the new user into the database. it will record the account in $DB_central which can be $DB or another one depending your DB config

Parameters
$data : array<string|int, mixed>

User registration data.

Return values
bool

True if account was created, false otherwise.

create_instance()

Creates the global instance $USER of the User class.

public static create_instance() : void

email_exists()

Checks if a email already exists.

public email_exists(string $email) : bool
Parameters
$email : string

to check.

Return values
bool

true,false

generate_activation_code()

Generates an activation code for the user account.

public generate_activation_code(int $id) : string|true|null
Parameters
$id : int

User ID.

Return values
string|true|null

Activation code, true if already active, or null on error.

get_connection_duration()

Returns the duration (in seconds) of the current connection.

public get_connection_duration() : int
Return values
int

Connection duration in seconds.

get_error_list()

Returns the current error list.

public get_error_list() : array<string|int, mixed>
Return values
array<string|int, mixed>

Error messages.

get_message_list()

Returns the current message list.

public get_message_list() : array<string|int, mixed>
Return values
array<string|int, mixed>

Informative messages.

get_user_agent()

Returns the current user agent string.

public get_user_agent() : string
Return values
string

User agent.

login_exists()

Checks if a login already exists.

public login_exists(string $login) : bool
Parameters
$login : string

to check.

Return values
bool

true , false

reset()

Resets the user session and connection state.

public reset([bool $bloquer = false ]) : void
Parameters
$bloquer : bool = false

If true, adds a "blocked" error message.

restricted_edit_modules()

Returns the list of modules with restricted editing for the user's group(s).

public restricted_edit_modules([int $id_user_data = 0 ]) : array<string|int, mixed>
Parameters
$id_user_data : int = 0

Optional. User ID to check (defaults to current user).

Return values
array<string|int, mixed>

List of restricted module names.


        
On this page

Search results