Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 로그인 API 작성 #26

Merged
merged 9 commits into from
Jan 11, 2024
File renamed without changes.
5 changes: 0 additions & 5 deletions backend/auth/models.py

This file was deleted.

File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions backend/auth/apps.py → backend/login/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.apps import AppConfig


class AuthConfig(AppConfig):
class LoginConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'auth'
name = 'login'
Empty file.
3 changes: 3 additions & 0 deletions backend/login/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Empty file.
37 changes: 37 additions & 0 deletions backend/login/schema/responses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from drf_yasg import openapi


common_login_response_schema = {
302: openapi.Response(
description="Change description",
headers={
"Location": {
"type": "string",
"description": "Redirect URI",
"format": "uri",
}
},
schema=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
"Location": openapi.Schema(
type=openapi.TYPE_STRING,
description="Redirect URI",
format=openapi.FORMAT_URI,
pattern=r"^/login/authorization\?code={code}&" + "state={state}&is_new_user=(true|false)$",
)
},
),
examples={
"application/json": {
"Location": "/login/authorization?code=1234567890&state=1234567890&is_new_user=true"
}
}
)
}

google_login_response_schema = common_login_response_schema.copy()
google_login_response_schema[302].description = "구글 인증 후 '/login/authorization'으로 리다이렉트"

ft_login_response_schema = common_login_response_schema.copy()
ft_login_response_schema[302].description = "42 인증 후 '/login/authorization'으로 리다이렉트"
File renamed without changes.
8 changes: 8 additions & 0 deletions backend/login/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from .views import GoogleLoginView, FTLoginView


urlpatterns = [
path('google/', GoogleLoginView.as_view(), name="google_login"),
path('42/', FTLoginView.as_view(), name="login_42"),
]
29 changes: 29 additions & 0 deletions backend/login/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# login/views.py
from rest_framework.views import APIView
from rest_framework.response import Response
from drf_yasg.utils import swagger_auto_schema
from .schema.responses import ft_login_response_schema, google_login_response_schema


class GoogleLoginView(APIView):
@swagger_auto_schema(
tags=["login"],
operation_summary="구글 OAuth 로그인",
operation_description="구글 OAuth 로그인 후 '/login/authorization'으로 리다이렉트",
responses=google_login_response_schema,
)
def get(self, request):
return Response(status=302, data={"message": "구글 OAuth 로그인"})


class FTLoginView(APIView):
@swagger_auto_schema(
tags=["login"],
operation_id="42_login",
operation_summary="42 OAuth 로그인",
operation_description="42 OAuth 로그인 후 '/login/authorization'으로 리다이렉트",
responses=ft_login_response_schema,
)
def get(self, request):
return Response(status=302, data={"message": "42 OAuth 로그인"})

18 changes: 6 additions & 12 deletions backend/src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ENV_PATH = os.path.join(BASE_DIR, '..', '.env')


env = environ.Env()

env.read_env(env_file=ENV_PATH)
Expand All @@ -42,10 +41,10 @@
},
'handlers': {
'logstash': {
'level': 'INFO', # 모든 로그 레벨 포함
'level': 'INFO', # 모든 로그 레벨 포함
'class': 'logstash.TCPLogstashHandler',
'host': 'logstash_container', # Logstash 서비스의 컨테이너 이름
'port': 5333, # Logstash 컨테이너가 로그를 수신하는 포트
'host': 'logstash_container', # Logstash 서비스의 컨테이너 이름
'port': 5333, # Logstash 컨테이너가 로그를 수신하는 포트
'version': 1,
'message_type': 'logstash',
'fqdn': False,
Expand All @@ -55,20 +54,18 @@
'loggers': {
'django': {
'handlers': ['logstash'],
'level': 'DEBUG', # 모든 로그 레벨 포함
'level': 'DEBUG', # 모든 로그 레벨 포함
'propagate': True,
},
# 필요에 따라 추가 로거 정의
},
}


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
Expand All @@ -78,8 +75,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'drf_yasg',
'rest_framework',
'drf_yasg',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -123,7 +120,6 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

Expand All @@ -142,7 +138,6 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

Expand All @@ -154,7 +149,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

Expand Down
18 changes: 5 additions & 13 deletions backend/src/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,22 @@
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

router = routers.DefaultRouter()

schema_view = get_schema_view(
openapi.Info(
title="ft_transcendence API",
default_version="v1.0.0",
description="Test description",
description="GunGonGamLee의 ft_transcendence API 문서입니다.",
terms_of_service="https://www.google.com/policies/terms/",
),
public=True,
permission_classes=[permissions.AllowAny, ],
)

urlpatterns = [
path('swagger<format>/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('admin/', admin.site.urls),
path('login/', include('login.urls')),
]

# DEBUG 모드일 경우, ui 없이 swagger view를 사용할 수 있도록 설정
if settings.DEBUG:
urlpatterns += [
re_path(r'^swagger(?P<format>\.json|\.yaml)$',
schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^swagger/$', schema_view.with_ui('swagger',
cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^redoc/$', schema_view.with_ui('redoc',
cache_timeout=0), name='schema-redoc'),
]
Empty file added backend/users/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions backend/users/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions backend/users/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class UsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'users'
Empty file.
3 changes: 3 additions & 0 deletions backend/users/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions backend/users/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
File renamed without changes.
3 changes: 0 additions & 3 deletions volumes/elasticsearch/config/elasticsearch.yml

This file was deleted.

8 changes: 0 additions & 8 deletions volumes/logstash/config/logstash.yml

This file was deleted.