File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-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
8
+
7
9
urlpatterns = [
8
10
path ("auth/" , include ("dj_rest_auth.urls" )),
9
11
path ("account/login/" , IdLogin .as_view (), name = 'account_login' ),
13
15
path ("auth/github/login/" , GitHubLogin .as_view (), name = "github_login" ),
14
16
path ("auth/google/login/" , GoogleLogin .as_view (), name = "google_login" ),
15
17
#path("my-page/payments", MyPage.as_view())
16
- path ("my-page/payments/" , mypage_payments )
18
+ path ("my-page/payments/" , mypage_payments ),
19
+
20
+ # Endpoints for Seesion Based Login
21
+ path ("api/login/" , login_api , name = "login-api" ),
22
+ # path("api/logout/", )
23
+
17
24
]
Original file line number Diff line number Diff line change 2
2
from allauth .socialaccount .providers .google .views import GoogleOAuth2Adapter
3
3
from allauth .socialaccount .providers .oauth2 .client import OAuth2Client
4
4
from dj_rest_auth .registration .views import SocialLoginView
5
+
5
6
from django .conf import settings
6
7
from django .contrib .auth .decorators import login_required
7
8
from django .shortcuts import render
9
+ from django .contrib .auth import login , logout , authenticate
10
+
11
+ from rest_framework .response import Response
8
12
from rest_framework .views import APIView
13
+ from rest_framework .decorators import api_view
9
14
10
15
import payment
11
16
@@ -37,3 +42,24 @@ def mypage_payments(request):
37
42
payment_list = payment .models .Payment .objects .filter (user_id = request .user )
38
43
return render (request , 'account_mypage_payments.html' ,
39
44
context = {'payment_list' : payment_list })
45
+
46
+
47
+ @api_view (["POST" ])
48
+ def login_api (request ):
49
+
50
+ if request .user .is_authenticated :
51
+ return Response ({"msg" : "already logged in" })
52
+
53
+ user = authenticate (
54
+ request ,
55
+ username = request .data ["username" ],
56
+ password = request .data ["password" ]
57
+ )
58
+
59
+ login (request , user )
60
+
61
+ response_data = {
62
+ "msg" : "ok"
63
+ }
64
+ return Response (response_data )
65
+
You can’t perform that action at this time.
0 commit comments