Skip to content

Commit a4b7c7a

Browse files
committed
login
1 parent c90319c commit a4b7c7a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

account/urls.py

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

55
from .views import IdLogin, Logout
66

7+
from .views import login_api
8+
79
urlpatterns = [
810
path("auth/", include("dj_rest_auth.urls")),
911
path("account/login/", IdLogin.as_view(), name='account_login'),
@@ -13,5 +15,10 @@
1315
path("auth/github/login/", GitHubLogin.as_view(), name="github_login"),
1416
path("auth/google/login/", GoogleLogin.as_view(), name="google_login"),
1517
#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+
1724
]

account/views.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter
33
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
44
from dj_rest_auth.registration.views import SocialLoginView
5+
56
from django.conf import settings
67
from django.contrib.auth.decorators import login_required
78
from django.shortcuts import render
9+
from django.contrib.auth import login, logout, authenticate
10+
11+
from rest_framework.response import Response
812
from rest_framework.views import APIView
13+
from rest_framework.decorators import api_view
914

1015
import payment
1116

@@ -37,3 +42,24 @@ def mypage_payments(request):
3742
payment_list = payment.models.Payment.objects.filter(user_id=request.user)
3843
return render(request, 'account_mypage_payments.html',
3944
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+

0 commit comments

Comments
 (0)