mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-27 22:03:58 +00:00
Refactor and enhance device management and authentication features
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 4m12s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 4m12s
- Updated the `reverse_dhivehi_string` function to correct the range for combining characters. - Added new device handling in the health check view and integrated the `add_new_devices_to_omada` task. - Improved date handling in `CreateTemporaryUserView` to ensure proper string conversion. - Enhanced OTP sending by converting mobile numbers to strings. - Implemented MAC address validation in the `Device` model using a custom validator. - Removed unnecessary fields from the `CreateDeviceSerializer`. - Normalized MAC address format in the `DeviceListCreateAPIView`. - Updated the `djangopasswordlessknox` package to improve code consistency and readability. - Added migration to enforce MAC address validation in the database.
This commit is contained in:
13
api/views.py
13
api/views.py
@ -1,4 +1,5 @@
|
||||
# django imports
|
||||
import pprint
|
||||
from django.contrib.auth import login
|
||||
|
||||
# rest_framework imports
|
||||
@ -31,7 +32,8 @@ from typing import cast, Dict, Any
|
||||
from django.core.mail import send_mail
|
||||
from django.db.models import Q
|
||||
from api.sms import send_otp
|
||||
from .tasks import add, deactivate_expired_devices
|
||||
from .tasks import add, add_new_devices_to_omada
|
||||
from devices.models import Device
|
||||
|
||||
# local apps import
|
||||
from .serializers import (
|
||||
@ -60,7 +62,8 @@ class ErrorMessages:
|
||||
@api_view(["GET"])
|
||||
def healthcheck(request):
|
||||
add.delay(1, 2)
|
||||
deactivate_expired_devices.delay()
|
||||
# devices = Device.objects.filter(is_active=False).values()
|
||||
# add_new_devices_to_omada.delay(new_devices=list(devices))
|
||||
return Response({"status": "Good"}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@ -117,7 +120,7 @@ class CreateTemporaryUserView(generics.CreateAPIView):
|
||||
|
||||
current_date = timezone.now()
|
||||
try:
|
||||
dob = timezone.datetime.strptime(dob, "%Y-%m-%d").date()
|
||||
dob = timezone.datetime.strptime(str(dob), "%Y-%m-%d").date()
|
||||
except ValueError:
|
||||
return Response(
|
||||
{"message": "Invalid date format for DOB. Use YYYY-MM-DD."}, status=400
|
||||
@ -193,7 +196,7 @@ class CreateTemporaryUserView(generics.CreateAPIView):
|
||||
formatted_time = otp_expiry.strftime("%d/%m/%Y %H:%M:%S")
|
||||
otp = temp_user.generate_otp()
|
||||
send_otp(
|
||||
temp_user.t_mobile,
|
||||
str(temp_user.t_mobile),
|
||||
otp,
|
||||
f"Your Registration SARLink OTP: {otp}. \nExpires at {formatted_time}. \n\n- SAR Link",
|
||||
)
|
||||
@ -263,7 +266,7 @@ class VerifyOTPView(generics.GenericAPIView):
|
||||
User.objects.create_user(
|
||||
first_name=temp_user.t_first_name,
|
||||
last_name=temp_user.t_last_name,
|
||||
username=temp_user.t_username,
|
||||
username=str(temp_user.t_username),
|
||||
password="",
|
||||
address=temp_user.t_address,
|
||||
mobile=temp_user.t_mobile,
|
||||
|
Reference in New Issue
Block a user