Skip to content

Commit

Permalink
test: Login/out
Browse files Browse the repository at this point in the history
  • Loading branch information
idabblewith committed May 13, 2024
1 parent e95ab3a commit 6a3458d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion config/dbca_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down
20 changes: 18 additions & 2 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6a3458d

Please sign in to comment.