Overview
The Aqua-IoT dashboard implements Django’s built-in authentication system to secure access to sensor data and monitoring capabilities. All dashboard features require authentication, ensuring that only authorized users can view and manage IoT sensor data.Authentication Flow
The authentication system follows a straightforward workflow:Login Implementation
The login view handles user authentication with Django’s built-in authentication backend:How It Works
- GET Request: Displays the login form when accessed via GET request
- POST Request: Processes login credentials when form is submitted
- Authentication: Uses Django’s
authenticate()function to verify credentials - Active Check: Ensures the user account is active before granting access
- Session Start: Calls Django’s
login()to create an authenticated session - Redirect: Redirects to the home dashboard upon successful login
The authentication view is located at
sensores/views.py:41 and is accessible at the /login/ URL route.Logout Implementation
Users can securely end their session using the logout functionality:Logout Process
- Calls Django’s
logout()function to terminate the user session - Clears all session data and authentication tokens
- Returns the user to the login page for re-authentication
Protected Routes
All main dashboard views require authentication before allowing access:/- Main dashboard (home view)/temp-aquario/- Aquarium temperature monitoring/temp-plantas/- Plant temperature monitoring/umidade/- Humidity monitoring/nivel/- Water level monitoring/ldr/- Light sensor monitoring/tds/- Water quality monitoring
API Authentication
The REST API endpoints also require authentication using Django REST Framework’s permission classes:All API viewsets use
IsAuthenticated permission class to ensure secure API access.Protected API Endpoints
All REST API endpoints require authentication:Aquarium Temperature
/api/temperatura-aquario/ - POST endpoint for aquarium temperature dataPlant Temperature
/api/temperatura-plantas/ - POST endpoint for plant temperature dataHumidity
/api/umidade/ - POST endpoint for humidity sensor dataWater Level
/api/nivel/ - POST endpoint for water level sensor dataLight Sensor
/api/ldr/ - POST endpoint for light sensor dataWater Quality
/api/tds/ - POST endpoint for TDS sensor dataSecurity Best Practices
Password Security
Password Security
Django automatically hashes passwords using PBKDF2 algorithm with SHA256. Never store or transmit passwords in plain text.
Session Management
Session Management
Django creates secure session cookies with HTTP-only flags. Sessions expire based on your Django settings configuration.
CSRF Protection
CSRF Protection
All POST requests include CSRF token validation to prevent cross-site request forgery attacks.
Active User Check
Active User Check
The authentication system verifies that user accounts are active (
user.is_active) before granting access.Authentication URL Routes
Authentication routes are defined in the URL configuration:Troubleshooting
Login Failed
Login Failed
- Verify username and password are correct
- Ensure the user account is active in Django admin
- Check that the user exists in the database
Automatic Logout
Automatic Logout
- Check session timeout settings in Django configuration
- Verify browser allows cookies
- Ensure session middleware is properly configured
API Authentication Error
API Authentication Error
- Confirm authentication token is included in API requests
- Verify the token is valid and not expired
- Check that the user has necessary permissions
Next Steps
Monitoring Sensors
Learn how to monitor sensors after authentication
API Reference
Integrate IoT devices using authenticated API calls
