Skip to content

Commit f1bb250

Browse files
committed
logout
1 parent a4b7c7a commit f1bb250

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

account/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .views import IdLogin, Logout
66

7-
from .views import login_api
7+
from .views import login_api, login_api_test, logout_api
88

99
urlpatterns = [
1010
path("auth/", include("dj_rest_auth.urls")),
@@ -19,6 +19,7 @@
1919

2020
# Endpoints for Seesion Based Login
2121
path("api/login/", login_api, name="login-api"),
22+
path("api/logout/", logout_api, name="logout-api"),
2223
# path("api/logout/", )
2324

2425
]

account/views.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,34 @@ def login_api(request):
6363
}
6464
return Response(response_data)
6565

66+
@api_view(["POST"])
67+
def logout_api(request):
68+
69+
if not request.user.is_authenticated:
70+
return Response({"msg": "not logged in"})
71+
72+
logout(request)
73+
74+
response_data = {
75+
"msg": "ok"
76+
}
77+
return Response(response_data)
78+
79+
@api_view(["GET"])
80+
def login_api_test(request):
81+
82+
if request.user.is_authenticated:
83+
return Response({"msg": "already logged in"})
84+
85+
user = authenticate(
86+
request,
87+
username="admin",
88+
password="admin"
89+
)
90+
91+
login(request, user)
92+
93+
response_data = {
94+
"msg": "ok"
95+
}
96+
return Response(response_data)

0 commit comments

Comments
 (0)