diff --git a/config/dbca_middleware.py b/config/dbca_middleware.py index 8a030ee1..44499919 100644 --- a/config/dbca_middleware.py +++ b/config/dbca_middleware.py @@ -10,6 +10,10 @@ from django.conf import settings from users.models import UserProfile, UserWork +from rest_framework.response import Response +from rest_framework.status import ( + HTTP_200_OK, +) User = get_user_model() @@ -64,7 +68,8 @@ def __call__(self, request): print("Logging out") # self.save_request_meta_to_file(request.META) logout(request) - return HttpResponseRedirect(request.META["HTTP_X_LOGOUT_URL"]) + data = {"logoutUrl": request.META["HTTP_X_LOGOUT_URL"]} + return Response(data, HTTP_200_OK) user_auth = request.user.is_authenticated if not user_auth: diff --git a/users/views.py b/users/views.py index d8c423eb..e80c5563 100644 --- a/users/views.py +++ b/users/views.py @@ -83,8 +83,24 @@ class Logout(APIView): permission_classes = [IsAuthenticated] def post(self, req): - logout(req) - return Response({"ok": "Bye"}) + if settings.DEBUG: + logout(req) + return Response({"ok": "True"}) + else: + if ( + ( + req.path.startswith("/logout") + or req.path.startswith("/api/v1/users/log-out") + or req.path.startswith("/api/v1/users/logout") + ) + and "HTTP_X_LOGOUT_URL" in req.META + and req.META["HTTP_X_LOGOUT_URL"] + ): + print("Logging out") + # self.save_request_meta_to_file(request.META) + logout(req) + data = {"ok": "True", "logoutUrl": req.META["HTTP_X_LOGOUT_URL"]} + return Response(data, HTTP_200_OK) class ChangePassword(APIView):