La Comanda uses PHP native sessions for authentication. When a user logs in successfully, their identity and role are written intoDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/JAQA20/LaComanda/llms.txt
Use this file to discover all available pages before exploring further.
$_SESSION and used on every subsequent request to verify both identity and permissions. There are no JWTs or API tokens — all protected views rely on the session cookie that PHP sets automatically.
Login Flow
User submits credentials
The login form at
views/login.php sends a POST request to /public/api/loginController.php with the user’s email and password.Credential validation
loginController.php looks up the submitted email in the usuarios table. If no matching record is found, or if the account has activo = 0, the login is rejected with an error message.Password verification
The stored password hash is checked using
password_verify() against the bcrypt hash stored at registration. Plain-text passwords are never stored.Session initialised
On success,
session_start() is called (if not already active) and the following keys are written into $_SESSION. The SesionesActivas::registrar() method is also called to record the new session in the active sessions log.Session Data
After a successful login the following variables are available in$_SESSION for the duration of the session:
| Variable | Type | Description |
|---|---|---|
$_SESSION["usuario_id"] | int | Primary key of the authenticated user |
$_SESSION["nombre"] | string | User’s first name |
$_SESSION["apellido"] | string | User’s last name |
$_SESSION["email"] | string | User’s email address |
$_SESSION["rol_id"] | int | Role identifier (1–4) used by verificarRol() |
middleware/roles.php and by any view that needs to display the current user’s name or personalise its content.
Session Activity Tracking
La Comanda tracks which users are currently online through theSesionesActivas class. Session data is persisted in a flat JSON file (sesiones_activas.json) rather than the database, keeping the overhead minimal.
- registrar()
- tocarSesionActual()
- listarActivas()
- cerrarSesionActual()
Called immediately after a successful login. Writes a new entry to
sesiones_activas.json containing:session_id— the PHP session IDusuario_id,nombre,email,rol_id— copied from the authenticated userlogin_at— ISO-8601 timestamp of when the session startedultima_actividad— timestamp updated on every subsequent requestip— client IP addressuser_agent— browser/client stringpagina_actual— the URL of the page last visited
The 30-minute TTL (1800 seconds) only governs which sessions appear as “active” in the admin’s session viewer. It does not terminate the PHP session itself — actual session expiry is controlled by
session.gc_maxlifetime in your server’s php.ini.Password Reset
La Comanda provides a token-based password reset flow delivered over email via Mailtrap SMTP.Request a reset link
The user visits
views/forgotPassword.php and submits their email address. The form posts to /public/api/forgotPassword.php.Token generation
The API generates a cryptographically random 32-byte token using
random_bytes(32). The SHA-256 hash of that token is stored in the password_resets table alongside the user’s ID and a 60-minute expiry timestamp. The raw (unhashed) token is embedded in the reset link sent to the user.Email delivery
The reset link (
/views/resetPassword.php?token=...) is sent to the user’s registered email address via Mailtrap SMTP. The response returned to the browser is always the same generic message regardless of whether the email exists — this prevents email enumeration attacks.Set new password
The user clicks the link and lands on
views/resetPassword.php. The application hashes the URL token with SHA-256, looks it up in password_resets, and confirms it has not expired. The user then sets a new password, which is stored as a fresh password_hash(PASSWORD_DEFAULT) bcrypt hash.Logout
Logout is triggered by aPOST request to /public/api/logout.php. The endpoint:
- Calls
SesionesActivas::cerrarSesionActual()to move the session record to the history log. - Calls
session_destroy()to invalidate the PHP session and clear all$_SESSIONdata. - Redirects the browser to
views/login.php.
POST request for logout prevents the action from being triggered accidentally by link prefetching or browser history navigation.