File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 4
4
5
5
from .views import IdLogin , Logout
6
6
7
- from .views import login_api
7
+ from .views import login_api , login_api_test , logout_api
8
8
9
9
urlpatterns = [
10
10
path ("auth/" , include ("dj_rest_auth.urls" )),
19
19
20
20
# Endpoints for Seesion Based Login
21
21
path ("api/login/" , login_api , name = "login-api" ),
22
+ path ("api/logout/" , logout_api , name = "logout-api" ),
22
23
# path("api/logout/", )
23
24
24
25
]
Original file line number Diff line number Diff line change @@ -63,3 +63,34 @@ def login_api(request):
63
63
}
64
64
return Response (response_data )
65
65
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 )
You can’t perform that action at this time.
0 commit comments