2023-11-11 13:50:14 -05:00
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework import permissions, status
|
|
|
|
from rest_framework.response import Response
|
2023-12-11 06:43:49 -05:00
|
|
|
from django.contrib.auth import logout
|
2023-11-11 13:50:14 -05:00
|
|
|
from django.http import HttpRequest
|
|
|
|
from rest_framework.authentication import SessionAuthentication
|
2023-10-25 09:35:24 -04:00
|
|
|
|
2023-11-11 13:50:14 -05:00
|
|
|
class DeleteView(APIView):
|
|
|
|
permission_classes = (permissions.IsAuthenticated,)
|
|
|
|
authentication_classes = (SessionAuthentication,)
|
2023-11-30 07:05:46 -05:00
|
|
|
def delete(self, request: HttpRequest):
|
2023-11-30 19:29:56 -05:00
|
|
|
data: dict = request.data
|
|
|
|
|
|
|
|
password: str = data["password"]
|
|
|
|
if (password is None):
|
|
|
|
return Response({"password": ["This field may not be blank."]})
|
|
|
|
if (request.user.check_password(password) == False):
|
|
|
|
return Response({"password": ["Password wrong."]})
|
2023-11-11 13:50:14 -05:00
|
|
|
request.user.delete()
|
2023-12-11 06:43:49 -05:00
|
|
|
logout(request)
|
2023-11-11 13:50:14 -05:00
|
|
|
return Response("user deleted", status=status.HTTP_200_OK)
|