handle logout, #855

This commit is contained in:
Simon
2025-01-01 15:26:23 +07:00
parent 20e3b7b7ff
commit 86232b8628
5 changed files with 47 additions and 5 deletions

View File

@@ -5,5 +5,6 @@ from user import views
urlpatterns = [
path("login/", views.LoginApiView.as_view(), name="api-user-login"),
path("logout/", views.LogoutApiView.as_view(), name="api-user-logout"),
path("me/", views.UserConfigView.as_view(), name="api-user-me"),
]

View File

@@ -1,7 +1,7 @@
"""all user api views"""
from common.views import ApiBaseView
from django.contrib.auth import authenticate, login
from django.contrib.auth import authenticate, login, logout
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
from rest_framework.permissions import AllowAny
@@ -82,3 +82,14 @@ class LoginApiView(APIView):
return Response({"message": "Login successful"}, status=200)
return Response({"message": "Invalid credentials"}, status=400)
class LogoutApiView(ApiBaseView):
"""resolves to /api/user/logout/
POST: handle logout
"""
def post(self, request, *args, **kwargs):
"""logout on post request"""
logout(request)
return Response({"message": "Successfully logged out."}, status=200)