Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ginza/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'corsheaders'
] + CUSTOMIZED_APPS + THIRD_PARTY_APPS

MIDDLEWARE = [
Expand All @@ -40,6 +41,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
]

AUTH_USER_MODEL = 'user.User'
Expand Down
2 changes: 1 addition & 1 deletion ginza/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@

KAKAO_REST_API_KEY = env.str('KAKAO_REST_API_KEY')
KAKAO_REDIRECT_URI = env.str('KAKAO_REDIRECT_URI')
KAKAO_SECRET_KEY = env.str('KAKAO_SECRET_KEY')
KAKAO_SECRET_KEY = env.str('KAKAO_SECRET_KEY')
3 changes: 3 additions & 0 deletions ginza/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@
KAKAO_REST_API_KEY = env.str('KAKAO_REST_API_KEY')
KAKAO_REDIRECT_URI = env.str('KAKAO_REDIRECT_URI')
KAKAO_SECRET_KEY = env.str('KAKAO_SECRET_KEY')

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ coreschema==0.0.4
coverage==6.3.2
Deprecated==1.2.13
Django==3.2.13
django-cors-headers==3.12.0
django-environ==0.8.1
django-extensions==3.1.5
django-redis==5.2.0
Expand Down
18 changes: 18 additions & 0 deletions user/serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from rest_framework import serializers


class SignupRequestBodySerializer(serializers.Serializer):
def update(self, instance, validated_data):
pass

def create(self, validated_data):
pass

email = serializers.EmailField()
password = serializers.CharField()
name = serializers.CharField()
mobile = serializers.CharField(max_length=11)
birthday = serializers.DateField()
is_solar_calendar = serializers.BooleanField()
agreed_with_mkt_info_subscription = serializers.BooleanField()

4 changes: 2 additions & 2 deletions user/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.urls import path
from user.views import SignupView, LoginView, LogoutView, KakaoOAuthLoginView, KakaoOAuthLoginCallbackView
from user.views import SignupView, LoginView, LogoutView, KakaoOAuthLoginView
from util.common import API_COMMON_PATH

urlpatterns = [
path(API_COMMON_PATH + 'auth/signup', SignupView.as_view()),
path(API_COMMON_PATH + 'auth/login', LoginView.as_view()),
path(API_COMMON_PATH + 'auth/logout', LogoutView.as_view()),
path(API_COMMON_PATH + 'oauth/kakao/login', KakaoOAuthLoginView.as_view()),
path(API_COMMON_PATH + 'oauth/kakao/login/callback', KakaoOAuthLoginCallbackView.as_view())
# path(API_COMMON_PATH + 'oauth/kakao/login/callback', KakaoOAuthLoginCallbackView.as_view())
]

53 changes: 33 additions & 20 deletions user/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import http

import binascii
import json
import logging
Expand All @@ -7,17 +9,20 @@
from django.contrib.auth import authenticate, logout
from django.conf import settings
from django.shortcuts import redirect
from drf_yasg.utils import swagger_auto_schema
from ginza.redis import redis_conn
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from user.models import User, UserProfile
from user.serializer import SignupRequestBodySerializer

logger = logging.getLogger('api')


class SignupView(APIView):
@swagger_auto_schema(request_body=SignupRequestBodySerializer)
def post(self, request, *args, **kwargs):
try:
data = request.data
Expand Down Expand Up @@ -96,24 +101,29 @@ def post(self, request):


# reference: https://velog.io/@junsikchoi/Django%EB%A1%9C-%EC%B9%B4%EC%B9%B4%EC%98%A4-%EC%86%8C%EC%85%9C-%EB%A1%9C%EA%B7%B8%EC%9D%B8%EC%9D%84-%ED%95%B4%EB%B3%B4%EC%9E%90
class KakaoOAuthLoginCallbackView(APIView):
def get(self, request):
auth_code = request.GET.get('code')
kakao_token_api = 'https://kauth.kakao.com/oauth/token'
data = {
'grant_type': 'authorization_code',
'client_id': settings.KAKAO_REST_API_KEY,
'redirection_uri': settings.KAKAO_REDIRECT_URI,
'client_secret': settings.KAKAO_SECRET_KEY,
'code': auth_code
}
token_response = requests.post(kakao_token_api, data=data)
access_token = token_response.json().get('access_token')
user_info_response = requests.get('https://kapi.kakao.com/v2/user/me', headers={"Authorization": f'Bearer ${access_token}'})
response = {
'user_info': user_info_response.json()
}
return Response(response)
# class KakaoOAuthLoginCallbackView(APIView):
# def get(self, request):
# auth_code = request.GET.get('code')
# kakao_token_api = 'https://kauth.kakao.com/oauth/token'
# data = {
# 'grant_type': 'authorization_code',
# 'client_id': settings.KAKAO_REST_API_KEY,
# 'redirection_uri': settings.KAKAO_REDIRECT_URI,
# 'client_secret': settings.KAKAO_SECRET_KEY,
# 'code': auth_code
# }
# token_response = requests.post(kakao_token_api, data=data)
# access_token = token_response.json().get('access_token')
#
# headers = {
# "Authorization": f'Bearer ${access_token}',
# "Content-type": "application/x-www-form-urlencoded;charset=utf-8"
# }
# user_info_response = requests.get('https://kapi.kakao.com/v2/user/me', headers=headers)
# response = {
# 'user_info': user_info_response.json()
# }
# return Response(response)


class KakaoOAuthLoginView(APIView):
Expand All @@ -122,5 +132,8 @@ def get(self, request):
redirect_url = settings.KAKAO_REDIRECT_URI
url = "https://kauth.kakao.com/oauth/authorize?response_type=code&client_id={0}&redirect_uri={1}".\
format(client_id, redirect_url)
res = redirect(url)
return res

response = {
'url': url
}
return Response(status=http.HTTPStatus.OK, data=response)