Added Filters for the File

This commit is contained in:
2024-03-26 14:07:05 -04:00
parent 4c290154fc
commit d8e9e6d614
10 changed files with 485 additions and 8 deletions

View File

@@ -4,6 +4,8 @@ from rest_framework import status
from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated
def get_client_ip(request):
@@ -59,3 +61,24 @@ class SignupView(APIView):
)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class PollOnlineView(APIView):
authentication_classes = [TokenAuthentication]
permission_classes = [IsAuthenticated]
def post(self, request):
try:
user = request.user
ip_address = get_client_ip(request)
user.ip_address = ip_address
user.save()
return Response(
{
"Message": "IP address updated successfully",
"username": user.username,
},
status=status.HTTP_200_OK,
)
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)