Documentation Index
Fetch the complete documentation index at: https://mintlify.com/obando1998/Proyecto_UCP/llms.txt
Use this file to discover all available pages before exploring further.
UsuarioController
Controllers/UsuarioController.php
The UsuarioController manages user creation and administration. It provides administrator-only functionality for creating new user accounts and viewing existing users.
Overview
- Purpose: Create and manage system users
- Access Level: Admin only (grado = 1)
- Model Used:
UsuarioModel - View:
Views/admin/crearUsuario.php
Class Structure
UsuarioController.php
Methods
__construct()
Initializes the controller with strict admin-only authentication. Behavior:- Starts PHP session if not already active
- Checks for authenticated admin user (
$_SESSION['logged_in']AND$_SESSION['grado'] == 1) - Redirects to login page if not an administrator
- Instantiates
UsuarioModelfor data access
Unlike HomeController, this controller requires grado = 1 (Admin). Auxiliary (grado 2) and Consultation (grado 3) users cannot access this functionality.
crear()
Displays the user creation form and processes new user submissions. Route:index.php?url=usuario/crear
HTTP Methods:
- GET: Displays user creation form with list of existing users
- POST: Processes new user creation
Flag indicating user creation form submission (must be present)
Username (USR field). Automatically converted to uppercase and trimmed.
Password (PAS field). Trimmed but not hashed (stored as plain text).
Full name (NOMBRE field). Automatically converted to uppercase and trimmed.
User role level:
1= Admin (full access)2= Auxiliary (create returns)3= Consultation (view only)
- All fields required: Username, password, name, and grado must not be empty
- Username uniqueness: Checked via
UsuarioModel::existeUsuario() - Data sanitization:
- Username and name converted to uppercase
- All fields trimmed of whitespace
- Grado cast to integer
Success or error message to display to admin
Message type:
'success' or 'error' (for styling)List of all users from
UsuarioModel::listarTodos() for display in tableWorkflow
Example Usage
Creating a New Auxiliary User
Validation Errors
Empty Field Error
Empty Field Error
Duplicate Username Error
Duplicate Username Error
Security Considerations
Current Implementation Issues
- No password hashing: The
pasfield is stored directly without bcrypt or password_hash() - Plain text storage: Database contains readable passwords
- No password strength validation: No minimum length or complexity requirements
Recommended Improvements
View Integration
TheViews/admin/crearUsuario.php view receives:
$usuarios contains:
USR- UsernameNOMBRE- Full nameGRADO- Role level (1, 2, or 3)
The
PAS field is excluded from listarTodos() for security - passwords are not displayed in the user list.Related Components
- UsuarioModel - Database operations for user management
- AuthController - User authentication and login
- AuthModel - Username lookup for authentication
Database Operations
All database operations are delegated to UsuarioModel:Route Requirements
To access this controller from the navigation:index.php?url=usuario/crear or the navigation menu should include a link to this page.