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, 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  : mixed = 'user_action'
activate  : mixed = 'activate'
connect  : mixed = 'connect'
create  : mixed = 'create'
disconnect  : mixed = 'disconnect'
session_connection_data  : mixed = 'connection_data'
session_connection_identifier  : mixed = 'hicut'
session_connection_state  : mixed = 'connection_state'
session_try_identifier  : mixed = 'connection_try'
session_user_id  : mixed = 'id'
session_user_login  : mixed = 'login'
state_ban  : mixed = -1
state_logged  : mixed = 1
state_not_logged  : mixed = 0
user_identifier_cookie  : mixed = 'hlp_hicut'

Properties

$account_created  : bool|null
$account_identified  : bool
$admin  : bool
$connection_hash  : string|null
$connection_state  : int
$force_reload_delay  : int
$id  : int
$id_activated  : int
$login  : string
$nb_attempt  : int
$nb_attempt_account  : 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_user_agent()  : string
Returns the current user agent string.
get_user_identifier()  : string
Returns the identifier of the client context: the value stored in the ip field of users_connections, connection_try_logs and users_token, compared on every request to recognise an established connection and to count connection attempts.
group_can_delete()  : bool
Tells whether the user's groups allow deleting content.
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_identifier

public mixed session_connection_identifier = 'hicut'

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
public mixed user_identifier_cookie = 'hlp_hicut'

Properties

$account_created

public bool|null $account_created = null

Whether the account was successfully created.

$account_identified

public bool $account_identified = false

True when the login of the last attempt matches a known account.

$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).

$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.

$nb_attempt

public int $nb_attempt = 0

Number of connection attempts.

$nb_attempt_account

public int $nb_attempt_account = 0

Number of connection attempts counted on the account itself.

$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_user_agent()

Returns the current user agent string.

public get_user_agent() : string
Return values
string —

User agent.

get_user_identifier()

Returns the identifier of the client context: the value stored in the ip field of users_connections, connection_try_logs and users_token, compared on every request to recognise an established connection and to count connection attempts.

public get_user_identifier() : string

With Config::IP_IDENTIFIER (default, and when the constant is not defined) this is the client IP. When it is false a per-visitor cookie is used instead: proxies and anonymizers (Cloudflare, VPN) hand out a different IP from one request to the next, so an IP based fingerprint misses and disconnects the visitor.

Return values
string —

The client identifier.

group_can_delete()

Tells whether the user's groups allow deleting content.

public group_can_delete() : bool

Site administrators always can. Other users need at least one group whose group_data.delete flag is set; the right is not per module (see group_modules for module access), it gates the destructive operations of a module.

Return values
bool

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