Administrative User Control
Relevant source files
The following files were used as context for generating this wiki page:
The Administrative User Control system provides a robust framework for managing user lifecycles, account details, and access states within the application. It encompasses backend RESTful endpoints for CRUD operations and frontend services that facilitate profile management, registration, and state updates.
This system is designed to handle user identification via unique "slugs" and maintains security through password hashing and state-based access control (enabled/disabled status). It serves as the foundation for user-related interactions across the platform.
Sources: Back/Alumnos/Api/Controllers/UsuariosController.cs, Front/src/services/api.ts
System Architecture and Data Flow
The architecture follows a decoupled client-server model. The backend is implemented using ASP.NET Core controllers interacting with an Entity Framework Core context (IAplicacionBdContexto), while the frontend utilizes React with services based on Fetch or Axios for API communication.
Data Flow Overview
The following diagram illustrates the flow of data when an administrative action (such as modifying a user) is performed:
This flow ensures that data is consistently mapped between database entities and Data Transfer Objects (DTOs) before reaching the UI.
Sources: Front/src/services/api.js:27-72, Back/Alumnos/Api/Controllers/UsuariosController.cs:12-104
Backend Implementation details
The backend core resides in the UsuariosController, which manages the logic for user retrieval, registration, and modification.
Core Endpoints
| Method | Route | Description |
|---|---|---|
| GET | /usuarios | Retrieves a list of users filtered by name and enabled status. |
| GET | /usuarios/{slug} | Retrieves detailed information for a specific user. |
| POST | /usuarios | Registers a new user with an encrypted password. |
| PUT | /usuarios/{slug} | Updates existing user profile information. |
| PATCH | /usuarios/{slug} | Toggles the Habilitado (enabled) status of a user. |
Sources: Back/Alumnos/Api/Controllers/UsuariosController.cs:25-104
User State Management
User access is controlled through a "Habilitado" boolean flag. This is managed via a specific PATCH endpoint that utilizes the HabilitadoUsuarioDto.
Sources: Back/Alumnos/Api/Controllers/UsuariosController.cs:91-104
The registration process ensures that sensitive data like passwords are never stored in plain text by utilizing the IHasherServicio.
Sources: Back/Alumnos/Api/Controllers/UsuariosController.cs:51-69
Data Transfer Objects (DTOs)
The system uses specific DTOs to enforce strict data structures for different operations, preventing over-posting and ensuring technical accuracy.
User Model Specifications
| Field | Type | Required | Description |
|---|---|---|---|
| Slug | String | Yes (Updates) | Unique URL-friendly identifier for the user. |
| Nombre | String | Yes | User's first name. |
| ApellidoPaterno | String | Yes | Father's last name. |
| ApellidoMaterno | String | Yes | Mother's last name. |
| NombreUsuario | String | Yes | Unique login username. |
| Contraseña | String | Yes (Creation) | User password (hashed before storage). |
| Habilitado | Boolean | Yes | Account activation status. |
Sources: Back/Alumnos/Api/Comun/Modelos/Usuarios/CrearUsuarioDto.cs, Back/Alumnos/Api/Comun/Modelos/Usuarios/ModificarUsuarioDto.cs
Frontend Service Integration
The frontend interacts with the administrative control system through the usuariosService. It handles authentication headers and response parsing.
Service Methods
obtenerUsuarios(nombre, habilitado): Fetches a list of users, often used in administrative dashboards.modificarUsuario(slug, usuario): Sends aPUTrequest to update user details.cambiarHabilitado(slug, habilitado): Performs a partial update to enable/disable accounts.actualizarImagen(slug, imagen): Specifically handlesmultipart/form-datafor profile picture updates.
Sources: Front/src/services/api.js:27-66, Front/src/services/api.ts:55-116
Profile Management Logic
In profile.jsx, the system implements a "Draft and Save" pattern where users can toggle an editing mode.
const handleSave = async (e) => {
e.preventDefault();
const updateData = {
slug: userSlug,
nombre: formData.nombre,
// ... other fields
habilitado: true
};
await usuariosService.modificarUsuario(userSlug, updateData);
};
Sources: Front/src/pages/profile.jsx:87-107
Security and Validation
- Password Protection: Passwords are encrypted using
IHasherServicioduring both registration and modification if a new password is provided. Sources: Back/Alumnos/Api/Controllers/UsuariosController.cs:56, 83 - Authentication Headers: Every request made through
api.jsorapi.tsautomatically attaches a Bearer Token retrieved fromlocalStorage. Sources: Front/src/services/api.js:21-24, Front/src/services/api.ts:40-46 - Data Consistency: The
MapeoDtosutility ensures that only safe fields are exposed to the frontend, stripping sensitive internal identifiers or raw credentials during retrieval. Sources: Back/Alumnos/Api/Comun/Utilidades/MapeoDtos.cs:11-23
Summary
The Administrative User Control module provides a centralized mechanism for managing user identities. By utilizing a combination of slug-based identification, DTO-driven data exchange, and hashed credential storage, it ensures a secure and scalable approach to user management. The integration between the React-based profile management and the ASP.NET Core controllers allows for seamless administrative operations and user self-service updates.