Login
Authenticate a user and create a session.Request Parameters
The username for authentication. Must match a user in the system.
The user’s password. Must match the password stored for the username.
Request Format
The endpoint expects form-encoded data (Content-Type:application/x-www-form-urlencoded).
Response
On successful authentication:- Status: 302 Redirect
- Redirect:
/monitor(for admin users) or/(for regular users) - Session: Sets authentication cookie
- Status: 200 OK (re-renders login page)
- Message: Flash message “Usuario o contraseña incorrectos”
Code Examples
Implementation Details
The endpoint implementation (app.py:95-109):Default Credentials
The system initializes with default test users:| Username | Password | Role | |
|---|---|---|---|
| admin | 123 | [email protected] | Admin |
| empleado1 | 123 | [email protected] | User |
Logout
End the current user session.Response
- Status: 302 Redirect
- Redirect:
/login - Action: Clears authentication cookie
Code Examples
Session Management
The API uses Flask-Login for session management:- Sessions are stored in encrypted cookies
- The secret key is configured as
'clave_secreta_muy_segura' - Unauthorized requests are redirected to
/login - The
@login_requireddecorator protects authenticated endpoints