UsersModel
extends Model
in package
Class UsersModel
- Manages user accounts data layer
- Handles operations across 'customer' (credentials) and 'savecustomer' (profile) tables
Table of Contents
Properties
- $table : string
Methods
- activateUser() : mixed
- Activates a user account after successful email verification
- addUser() : bool|string
- Registers a new user by creating records in both required tables
- countUsers() : int
- Counts total registered standard users for admin statistics
- find() : mixed
- Finds a specific record by its ID.
- findAll() : array<string|int, mixed>|false
- Retrieves all records from the associated table.
- getEmailById() : object|false
- Fetches only the email address for a specific user
- getModeById() : string|null
- Retrieves the 2fa mode setting for the user
- getStatusById() : object|false
- Checks the account status (e.g., active, banned, pending)
- getUserByEmail() : object|false
- Finds a user by email, used primarily for password reset requests
- getUserById() : object|false
- Retrieves full user profile by internal id
- getUserByUsername() : object|false
- Retrieves user data by username for authentication
- requete() : PDOStatement|false
- Executes a SQL query (prepared or direct).
- setModeById() : mixed
- Updates the 2fa preference for a user
- updatePassword() : void
- Updates the user's password with a new hash
- validateNewPassword() : bool|string
- Validates password complexity and history requirements
Properties
$table
protected
string
$table
= 'Customer'
The database table associated with the model.
Methods
activateUser()
Activates a user account after successful email verification
public
activateUser(int $id_user) : mixed
Parameters
- $id_user : int
addUser()
Registers a new user by creating records in both required tables
public
addUser(string $email, string $username, string $password, string $lastname) : bool|string
Parameters
- $email : string
- $username : string
- $password : string
-
plain text password
- $lastname : string
Return values
bool|string —true on success, "duplicate" if email exists, false on error
countUsers()
Counts total registered standard users for admin statistics
public
countUsers() : int
Return values
intfind()
Finds a specific record by its ID.
public
find(int $id) : mixed
Parameters
- $id : int
-
The record identifier.
Return values
mixed —The record object or false if not found.
findAll()
Retrieves all records from the associated table.
public
findAll() : array<string|int, mixed>|false
Return values
array<string|int, mixed>|false —List of records.
getEmailById()
Fetches only the email address for a specific user
public
getEmailById(int $id_user) : object|false
Parameters
- $id_user : int
Return values
object|falsegetModeById()
Retrieves the 2fa mode setting for the user
public
getModeById(int $id_user) : string|null
Parameters
- $id_user : int
Return values
string|null —'2FA' or null
getStatusById()
Checks the account status (e.g., active, banned, pending)
public
getStatusById(int $id_user) : object|false
Parameters
- $id_user : int
Return values
object|falsegetUserByEmail()
Finds a user by email, used primarily for password reset requests
public
getUserByEmail(string $email) : object|false
Parameters
- $email : string
Return values
object|falsegetUserById()
Retrieves full user profile by internal id
public
getUserById(int $id_user) : object|false
Parameters
- $id_user : int
-
the user identifier
Return values
object|false —user data object or false if not found
getUserByUsername()
Retrieves user data by username for authentication
public
getUserByUsername(string $username) : object|false
Parameters
- $username : string
-
the login username
Return values
object|false —user data
requete()
Executes a SQL query (prepared or direct).
public
requete(string $sql[, array<string|int, mixed>|null $attributs = null ]) : PDOStatement|false
Parameters
- $sql : string
-
The SQL query string.
- $attributs : array<string|int, mixed>|null = null
-
Optional parameters for prepared statements.
Return values
PDOStatement|false —The result statement.
setModeById()
Updates the 2fa preference for a user
public
setModeById(int $id_user, string|null $mode) : mixed
Parameters
- $id_user : int
- $mode : string|null
-
'2FA' to enable, null to disable
updatePassword()
Updates the user's password with a new hash
public
updatePassword(int $userId, string $plainPassword) : void
Parameters
- $userId : int
- $plainPassword : string
validateNewPassword()
Validates password complexity and history requirements
public
validateNewPassword(int $userId, string $plainPassword) : bool|string
Parameters
- $userId : int
- $plainPassword : string
Return values
bool|string —true if valid, error message string otherwise