This documentation provides a comprehensive guide on how to use the User Management API. The API supports user registration, login, OTP verification, and password reset functionalities.
http://<your-domain>/accounts/
- Endpoint:
/register/ - Method:
POST - Description: Registers a new user and sends an OTP for email verification.
{
"email": "user@example.com",
"password": "your_password"
}- Success (201 Created)
{
"status": 200,
"message": "User created successfully. Check your email for OTP verification.",
"data": {
"email": "user@example.com"
}
}- Error (400 Bad Request)
{
"status": 400,
"message": "Something went wrong",
"data": {
"email": ["This field must be unique."]
}
}- Endpoint:
/login/ - Method:
POST - Description: Authenticates a user and returns access and refresh tokens.
{
"email": "user@example.com",
"password": "your_password"
}- Success (200 OK)
{
"status": 200,
"message": "Login successful",
"data": {
"email": "user@example.com",
"refresh": "<refresh_token>",
"access": "<access_token>"
}
}- Error (400 Bad Request)
{
"status": 400,
"message": "Invalid credentials: Incorrect password"
}- Endpoint:
/verify/ - Method:
POST - Description: Verifies the OTP sent to the user's email.
{
"email": "user@example.com",
"otp": 1234
}- Success (200 OK)
{
"status": 200,
"message": "User verified successfully."
}- Error (400 Bad Request)
{
"status": 400,
"message": "Invalid OTP."
}- Endpoint:
/password-reset/request/ - Method:
POST - Description: Sends a password reset email to the user.
{
"email": "user@example.com"
}- Success (200 OK)
{
"status": 200,
"message": "Password reset email sent."
}- Error (404 Not Found)
{
"status": 404,
"message": "Email not found."
}- Endpoint:
/password-reset/ - Method:
POST - Description: Resets the user's password using a token received in the password reset email.
{
"token": "<token>",
"new_password": "new_password"
}- Success (200 OK)
{
"status": 200,
"message": "Password has been reset successfully."
}- Error (400 Bad Request)
{
"status": 400,
"message": "Invalid token."
}All endpoints return standardized error messages, including:
400 Bad Request: Indicates invalid input data.404 Not Found: Indicates that the requested resource was not found.
This API provides essential functionalities for user management, including registration, login, OTP verification, and password resetting. Ensure to handle responses appropriately and validate user input to improve the user experience. For any issues or feature requests, please contact the development team.
This documentation outlines how to use the Attendance Management API. This API allows you to retrieve attendance records from devices, providing insights into user attendance for a given day.
http://<your-domain>/api/
- Endpoint:
/attendance/today/ - Method:
GET - Description: Retrieves today's attendance records for a specified device based on the username.
- username (required): The unique username of the device.
GET /api/attendance/today/?username=device_username
- Success (200 OK)
[
{
"user_id": 1,
"user_name": "John Doe",
"privilege": "Admin",
"password": "hashed_password",
"group_id": "group_1",
"in_time": "2024-09-21T09:00:00Z",
"out_time": "2024-09-21T17:00:00Z",
"device_name": "Device Name",
"device_area": "Device Area",
"device_username": "device_username"
},
...
]- Error (400 Bad Request)
{
"error": "Username parameter is required."
}- Error (403 Forbidden)
{
"error": "You do not have permission to access this device."
}- Error (404 Not Found)
{
"error": "Device not found."
}- Error (500 Internal Server Error)
{
"error": "<error_message>"
}Here’s how you can make a GET request to the attendance API using Laravel:
use Illuminate\Support\Facades\Http;
function getTodaysAttendance($username) {
$response = Http::withToken('your_api_token')->get('http://<your-domain>/api/attendance/today/', [
'username' => $username,
]);
if ($response->successful()) {
return $response->json();
} elseif ($response->status() == 400) {
return ['error' => 'Username parameter is required.'];
} elseif ($response->status() == 404) {
return ['error' => 'Device not found.'];
} elseif ($response->status() == 403) {
return ['error' => 'You do not have permission to access this device.'];
} else {
return ['error' => 'An unexpected error occurred.'];
}
}
// Usage
$attendanceRecords = getTodaysAttendance('device_username');
print_r($attendanceRecords);Here’s how you can make a GET request to the attendance API using Python with the requests library:
import requests
def get_todays_attendance(username):
url = 'http://<your-domain>/api/attendance/today/'
headers = {'Authorization': 'Bearer your_api_token'}
response = requests.get(url, headers=headers, params={'username': username})
if response.status_code == 200:
return response.json()
elif response.status_code == 400:
return {"error": "Username parameter is required."}
elif response.status_code == 404:
return {"error": "Device not found."}
elif response.status_code == 403:
return {"error": "You do not have permission to access this device."}
else:
return {"error": f"An unexpected error occurred: {response.text}"}
# Usage
attendance_records = get_todays_attendance('device_username')
print(attendance_records)This updated documentation provides a comprehensive overview of how to access today’s attendance records through your API, including error handling and sample code in both Laravel and Python. Be sure to replace <your-domain> and your_api_token with actual values when implementing the code.
This API requires authentication. Ensure that you include a valid token in the request headers:
Authorization: Bearer <your_access_token>
The API returns standardized error messages, including:
400 Bad Request: Indicates that the request is missing required parameters.404 Not Found: Indicates that the specified device does not exist.500 Internal Server Error: Indicates an unexpected error occurred on the server.
The Attendance Management API provides a straightforward way to access today's attendance records from specified devices. Ensure proper authentication and provide the necessary parameters to retrieve the desired data. For any issues or feature requests, please contact the development team.
Certainly! Below is a structured documentation for the CRUD API for the Device model in your Django REST Framework application. This documentation includes endpoint descriptions, request/response formats, and example usage.
The Device CRUD API allows users to create, retrieve, update, and delete devices in the system. Each device has attributes such as name, area, username, IP address, and port.
http://<your-domain>/api/
This API requires authentication. Use token-based authentication (e.g., JWT) to access the endpoints. Include the token in the Authorization header as follows:
Authorization: Bearer <your_token>
- Endpoint:
/devices/ - Method:
POST - Description: Creates a new device.
- Request Headers:
Content-Type: application/jsonAuthorization: Bearer <your_token>
- Request Body:
{
"name": "Device 1",
"area": "Office",
"username": "device1",
"ip_address": "192.168.1.10",
"port": 8080
}- Response:
- Status Code:
201 Created - Response Body:
- Status Code:
{
"id": "uuid_value",
"name": "Device 1",
"area": "Office",
"username": "device1",
"ip_address": "192.168.1.10",
"port": 8080,
"created_at": "2024-09-21T12:34:56Z",
"updated_at": "2024-09-21T12:34:56Z"
}- Endpoint:
/devices/ - Method:
GET - Description: Retrieves a list of all devices.
- Request Headers:
Authorization: Bearer <your_token>
- Response:
- Status Code:
200 OK - Response Body:
- Status Code:
[
{
"id": "uuid_value_1",
"name": "Device 1",
"area": "Office",
"username": "device1",
"ip_address": "192.168.1.10",
"port": 8080,
"created_at": "2024-09-21T12:34:56Z",
"updated_at": "2024-09-21T12:34:56Z"
},
{
"id": "uuid_value_2",
"name": "Device 2",
...
}
]- Endpoint:
/devices/<device_id>/ - Method:
GET - Description: Retrieves details of a specific device by its ID.
- Request Headers:
Authorization: Bearer <your_token>
- Response:
- Status Code:
200 OK - Response Body:
- Status Code:
{
"id": "uuid_value_1",
"name": "Device 1",
"area": "Office",
"username": "device1",
"ip_address": "192.168.1.10",
"port": 8080,
"created_at": "2024-09-21T12:34:56Z",
"updated_at": "2024-09-21T12:34:56Z"
}If the device is not found:
- Status Code:
404 Not Found - Response Body:
{
"detail": "Not found."
}- Endpoint:
/devices/<device_id>/ - Method:
PUTorPATCH - Description: Updates details of a specific device.
- Request Headers:
Content-Type: application/jsonAuthorization: Bearer <your_token>
- Request Body:
{
"name": "Updated Device Name",
"area": "Updated Area",
"username": "updated_device_username",
"ip_address": "192.168.1.20",
"port": 9090
}- Response:
- Status Code:
200 OK - Response Body:
- Status Code:
{
"id": "uuid_value_1",
...
}If the device is not found:
- Status Code:
404 Not Found - Response Body:
{
"detail": "Not found."
}- Endpoint:
/devices/<device_id>/ - Method:
DELETE - Description: Deletes a specific device by its ID.
- Request Headers:
Authorization: Bearer <your_token>
If successful:
- Status Code:
204 No Content
If the device is not found:
- Status Code:
404 Not Found - Response Body:
{
"detail": "Not found."
}This documentation provides an overview of the CRUD operations available for managing devices in your Django REST Framework application. Ensure you have proper authentication set up to access these endpoints and test them using tools like Postman or cURL for effective development and debugging.
Feel free to customize this documentation further based on your project requirements!