Esempio n. 1
0
 def put(self, request):
     admin = JWTAuthentication.validate_token(request)  
     serializer = UserStatusUpdateSerializer(data=request.data)
     if serializer.is_valid():
         data = serializer.validated_data
         user_status = data.get('user_status')  
         if JWTAuthentication.isAdmin(admin.id):
             try:
                 criterion1 = Q(deleted_at__isnull=True)
                 criterion2 = Q(id=data['id'])
                 user_info = User.objects.get(criterion1 & criterion2)
                 user_info.user_status_id = user_status
                 user_info.save()
                 user_info = User.objects.get(id=data['id'])
                 name = user_info.first_name
                 if user_info.user_status.name == "approved":
                     body = "Hi {},\n Congratulations, we have approved your registration.\
                         '\n To Login, please use email id and password provided at the time of registration.".format(name)
                     Util.send_email('Home Finder account update', body, '*****@*****.**', [user_info.email_id])
                 else:
                     body = "Hi {},\n Sorry, as provide information does not qaulify our standards,\
                          your registration can not be approved.\
                         '\n Please contact support for more information".format(name)
                     Util.send_email('Home Finder account update',body, '*****@*****.**', [user_info.email_id])
                 return JsonResponse({'message': 'Update successful'}, status=status.HTTP_201_CREATED)
             except Exception as ex:
                 return JsonResponse({'message': str(ex)}, status=status.HTTP_404_NOT_FOUND)
         else:
             return JsonResponse({'message': 'Admin authentication failed'}, status=status.HTTP_412_PRECONDITION_FAILED)
     else:
         return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 2
0
 def get(self, request):
     admin = JWTAuthentication.validate_token(request)
     if JWTAuthentication.isAdmin(admin.id):
         try:
             criterion1 = ~Q(role__name ='admin')
             pending_users = User.objects.filter(criterion1)
             if pending_users:
                 serializer = RetriveUsersSerializer(pending_users,many=True)
                 response_data = {'message':'Users retrival succesful','users_list': serializer.data}
                 return JsonResponse(response_data,status=status.HTTP_200_OK,safe=False)
             else:                    
                 return JsonResponse({'message': 'No user found with pending status'}, status=status.HTTP_404_NOT_FOUND)
         except Exception as ex:
             return JsonResponse({'message': str(ex)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     else:
         return JsonResponse({'message': 'Admin authentication failed'}, status=status.HTTP_412_PRECONDITION_FAILED)
Esempio n. 3
0
 def post(self, request):
     admin = JWTAuthentication.validate_token(request)
     serializer = UserStatusUpdateSerializer(data=request.data)
     if serializer.is_valid():
         data = serializer.validated_data
         user_id = data.get('id')
         user_status = data.get('user_status')
         reason = data.get('deleted_why')
         if JWTAuthentication.isAdmin(admin.id):
             try:
                 user = User.objects.get(id=user_id)
                 user.user_status_id= user_status
                 user.deleted_at = timezone.now()
                 user.deleted_why = reason
                 user.is_active = False
                 user.save()
                 return JsonResponse({'message': 'User deleted'}, status=status.HTTP_201_CREATED)
             except Exception as ex:
                 return JsonResponse({'message': str(ex)}, status=status.HTTP_404_NOT_FOUND)
         else:
             return JsonResponse({'message': 'Admin authentication failed'}, status=status.HTTP_412_PRECONDITION_FAILED)
     else:
         return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)