Skip to content

Commit

Permalink
added the login , logout and delete apis (#2493)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uttkarsh-raj authored Jul 29, 2024
1 parent fd399ad commit c885446
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from blt import settings
from company.views import ShowBughuntView
from website.api.views import (
AuthApiViewset,
BugHuntApiViewset,
BugHuntApiViewsetV2,
CompanyViewSet,
Expand Down Expand Up @@ -549,6 +550,7 @@
ProjectViewSet.as_view({"get": "list", "post": "create", "patch": "update"}),
name="projects_api",
),
path("auth/delete", AuthApiViewset.as_view({"delete": "delete"}), name="auth-delete-api"),
]

if settings.DEBUG:
Expand Down
18 changes: 18 additions & 0 deletions website/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
IssueScreenshot,
Points,
Project,
Token,
User,
UserProfile,
)
Expand Down Expand Up @@ -718,3 +719,20 @@ def list(self, request, *args, **kwargs):
{"count": len(project_data), "projects": project_data},
status=200,
)


class AuthApiViewset(viewsets.ModelViewSet):
http_method_names = ("delete",)
permission_classes = (IsAuthenticated,)

def delete(self, request, *args, **kwargs):
try:
token = request.headers["Authorization"].split(" ")
user = Token.objects.get(key=token[1]).user
user_data = User.objects.get(username=user)
user_data.delete()
return Response({"success": True, "message": "User deleted successfully !!"})
except Token.DoesNotExist:
return Response({"success": False, "message": "User does not exists."})
except User.DoesNotExist:
return Response({"success": False, "message": "User does not exists."})

0 comments on commit c885446

Please sign in to comment.