TokensModel
extends Model
in package
Class TokensModel
- Manages secure tokens used for critical actions
- Handles lifecycle for 'validation', 'reinitialisation', and '2fa' types
Table of Contents
Properties
- $table : string
Methods
- consumeToken() : void
- Removes a token permanently after successful use
- deleteToken() : void
- Cleans up all expired tokens from the database
- find() : mixed
- Finds a specific record by its ID.
- findAll() : array<string|int, mixed>|false
- Retrieves all records from the associated table.
- generateToken() : string
- Generates a short-lived numeric token and stores it
- requete() : PDOStatement|false
- Executes a SQL query (prepared or direct).
- verifyToken() : mixed
- Checks if a token exists and is still within its validity window
Properties
$table
protected
string
$table
= 'Tokens'
The database table associated with the model.
Methods
consumeToken()
Removes a token permanently after successful use
public
consumeToken(string $token) : void
Parameters
- $token : string
deleteToken()
Cleans up all expired tokens from the database
public
deleteToken() : void
find()
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.
generateToken()
Generates a short-lived numeric token and stores it
public
generateToken(int $user_id, string $type) : string
Parameters
- $user_id : int
- $type : string
-
context (e.g. 'validation', '2fa')
Return values
string —the generated 6-digit code
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.
verifyToken()
Checks if a token exists and is still within its validity window
public
verifyToken(string $token) : mixed
Parameters
- $token : string
Return values
mixed —token object if valid, false otherwise