mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-26 06:09:41 +00:00
unrestrict logout and refresh token api while login in multiple device
This commit is contained in:
@ -45,11 +45,12 @@ class CustomMiddleware(object):
|
||||
device_type = str(request.META.get('HTTP_TYPE'))
|
||||
|
||||
api_endpoint = request.path
|
||||
unrestricted_api = ('/api/v1/user/login/', '/api/v1/logout/', '/api/v1/generate-token/')
|
||||
if request.user.is_authenticated:
|
||||
# device details
|
||||
if device_id:
|
||||
device_details = UserDeviceDetails.objects.filter(user=request.user, device_id=device_id).last()
|
||||
if not device_details and api_endpoint != '/api/v1/user/login/':
|
||||
if not device_details and api_endpoint not in unrestricted_api:
|
||||
custom_error = custom_error_response(ERROR_CODE['2037'], response_status=status.HTTP_404_NOT_FOUND)
|
||||
response = custom_response(custom_error)
|
||||
if user_type and str(user_type) == str(NUMBER['one']):
|
||||
|
@ -147,8 +147,8 @@ SUCCESS_CODE = {
|
||||
"3018": "Task created successfully",
|
||||
"3019": "Support Email sent successfully",
|
||||
"3020": "Logged out successfully.",
|
||||
"3021": "Add junior successfully",
|
||||
"3022": "Remove junior successfully",
|
||||
"3021": "Added junior successfully",
|
||||
"3022": "Removed junior successfully",
|
||||
"3023": "Junior is approved successfully",
|
||||
"3024": "Junior request is rejected successfully",
|
||||
"3025": "Task is approved successfully",
|
||||
|
@ -233,23 +233,16 @@ class TaskSerializer(serializers.ModelSerializer):
|
||||
# update image of the task
|
||||
images = self.context['image']
|
||||
junior_ids = self.context['junior_data']
|
||||
print("junior_ids==>", junior_ids, '==>', type(junior_ids))
|
||||
print()
|
||||
junior_data = junior_ids[0].split(',')
|
||||
print("junior_data[0==>", junior_data, '==>', type(junior_data))
|
||||
tasks_created = []
|
||||
|
||||
for junior_id in junior_data:
|
||||
print("junior_id==>",junior_id,'==>',type(junior_id))
|
||||
task_data = validated_data.copy()
|
||||
task_data['guardian'] = guardian
|
||||
task_data['default_image'] = images
|
||||
task_data['junior'] = Junior.objects.filter(id=junior_id).last()
|
||||
print("task_data===>", task_data, '===>', type(task_data))
|
||||
print("task_data['junior']===>", task_data['junior'], '===>', type(task_data['junior']))
|
||||
instance = JuniorTask.objects.create(**task_data)
|
||||
tasks_created.append(instance)
|
||||
print("tasks_created==>", tasks_created, '==>', type(tasks_created))
|
||||
return instance
|
||||
|
||||
class GuardianDetailSerializer(serializers.ModelSerializer):
|
||||
|
@ -178,13 +178,8 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
||||
try:
|
||||
image = request.data['default_image']
|
||||
juniors = request.data['junior'].split(',')
|
||||
print("juniors===>", juniors, '===>', type(juniors))
|
||||
print()
|
||||
|
||||
for junior in juniors:
|
||||
print("junior===>", junior, '===>', type(junior))
|
||||
junior_id = Junior.objects.filter(id=junior).last()
|
||||
print("junior_id===>", junior_id, '===>', type(junior_id))
|
||||
if junior_id:
|
||||
guardian_data = Guardian.objects.filter(user=request.user).last()
|
||||
index = junior_id.guardian_code.index(guardian_data.guardian_code)
|
||||
@ -197,7 +192,6 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
||||
if not junior.isnumeric():
|
||||
"""junior value must be integer"""
|
||||
return custom_error_response(ERROR_CODE['2047'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
print("request.data===>", request.data, '===>', type(request.data))
|
||||
data = request.data
|
||||
if 'https' in str(image):
|
||||
image_data = image
|
||||
@ -208,11 +202,7 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
||||
image_url = upload_image_to_alibaba(image, filename)
|
||||
image_data = image_url
|
||||
data.pop('default_image')
|
||||
print("data===>",data,'===>',type(data))
|
||||
junior_data = data.pop('junior')
|
||||
print()
|
||||
print("data===>", data, '===>', type(data))
|
||||
print("junior_data===>", junior_data, '===>', type(junior_data))
|
||||
# use TaskSerializer serializer
|
||||
serializer = TaskSerializer(context={"user":request.user, "image":image_data,
|
||||
"junior_data":junior_data}, data=data)
|
||||
@ -222,7 +212,7 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
||||
|
||||
send_notification.delay(TASK_ASSIGNED, request.auth.payload['user_id'], GUARDIAN,
|
||||
junior_id.auth.id, {'task_id': task.id})
|
||||
return custom_response(SUCCESS_CODE['3018'], serializer.data, response_status=status.HTTP_200_OK)
|
||||
return custom_response(SUCCESS_CODE['3018'], response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||
else:
|
||||
return custom_error_response(ERROR_CODE['2047'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
@ -181,32 +181,32 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
# database query logs settings
|
||||
# Allows us to check db hits
|
||||
# useful to optimize db query and hit
|
||||
# LOGGING = {
|
||||
# "version": 1,
|
||||
# "filters": {
|
||||
# "require_debug_true": {
|
||||
# "()": "django.utils.log.RequireDebugTrue"
|
||||
# }
|
||||
# },
|
||||
# "handlers": {
|
||||
# "console": {
|
||||
# "level": "DEBUG",
|
||||
# "filters": [
|
||||
# "require_debug_true"
|
||||
# ],
|
||||
# "class": "logging.StreamHandler"
|
||||
# }
|
||||
# },
|
||||
# # database logger
|
||||
# "loggers": {
|
||||
# "django.db.backends": {
|
||||
# "level": "DEBUG",
|
||||
# "handlers": [
|
||||
# "console"
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
LOGGING = {
|
||||
"version": 1,
|
||||
"filters": {
|
||||
"require_debug_true": {
|
||||
"()": "django.utils.log.RequireDebugTrue"
|
||||
}
|
||||
},
|
||||
"handlers": {
|
||||
"console": {
|
||||
"level": "DEBUG",
|
||||
"filters": [
|
||||
"require_debug_true"
|
||||
],
|
||||
"class": "logging.StreamHandler"
|
||||
}
|
||||
},
|
||||
# database logger
|
||||
"loggers": {
|
||||
"django.db.backends": {
|
||||
"level": "DEBUG",
|
||||
"handlers": [
|
||||
"console"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||
|
Reference in New Issue
Block a user