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

Junsung #19

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
64 changes: 48 additions & 16 deletions Django/NoUgly/NoUgly/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django.core.exceptions import ImproperlyConfigured
import datetime
import os

from datetime import timedelta
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand All @@ -31,7 +31,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('NOUGLY_DEBUG', False)

ALLOWED_HOSTS = ["*"]
ALLOWED_HOSTS = ['*']

# 배포 시
# ALLOWED_HOSTS = ['cmsong111.pythonanywhere.com']
Expand All @@ -46,25 +46,29 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',

# DRF Authentication 이용
'rest_framework',
'rest_framework.authtoken',
'rest_auth',

'rest_framework_simplejwt.token_blacklist',
# 회원가입
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'rest_auth.registration',
'dj_rest_auth',
'dj_rest_auth.registration',
'django_filters',

# myapp
'accounts',
'store',
# 'phonenumber_field',


# provider
'allauth.socialaccount.providers.kakao',
'allauth.socialaccount.providers.naver',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -175,12 +179,32 @@

REST_USE_JWT = True

# 하나의 사이트에서 여러 domain을 가질 수 있는 기능, 사이트 ID를 강제로 지정한다.
SITE_ID = 1


MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


# Kakao, Naer 제공
SOCIALACCOUNT_PROVIDERS = {
'kakao': {
'APP': {
'client_id': os.environ.get('kakao_client_id'),
'secret': os.environ.get('kakao_secret'),
'key': ''
}
},
'naver': {
'APP': {
'client_id': os.environ.get('naver_client_id'),
'secret': os.environ.get('naver_secret'),
'key': ''
}
}
}

# DRF
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
Expand All @@ -190,9 +214,11 @@
],
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend', ],
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',

'dj_rest_auth.jwt_auth.JWTCookieAuthentication',

# 'rest_framework.authentication.TokenAuthentication',
# 'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.SessionAuthentication',
# 'rest_framework.authentication.BasicAuthentication',
],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
Expand All @@ -211,12 +237,18 @@
'LOGIN_SERIALIZER': 'accounts.serializers.UserLoginSerializer'
}

JWT_AUTH = {
'JWT_SECRET_KEY': SECRET_KEY,
'JWT_ALGORITHM': 'HS256', # 암호화 알고리즘
'JWT_ALLOW_REFRESH': True, # refresh 사용 여부
'JWT_EXPIRATION_DELTA': datetime.timedelta(days=7), # 유효기간 설정
# JWT 토큰 갱신 유효기간
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=28),
# import datetime 상단에 import 하기
# JWT_AUTH = {
# 'JWT_SECRET_KEY': SECRET_KEY,
# 'JWT_ALGORITHM': 'HS256', # 암호화 알고리즘
# 'JWT_ALLOW_REFRESH': True, # refresh 사용 여부
# 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=7), # 유효기간 설정
# # JWT 토큰 갱신 유효기간
# 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=28),
# # import datetime 상단에 import 하기
# }
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(hours=2),
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
'ROTATE_REFRESH_TOKENS': False, # Token 재발급 관련 설정
'BLACKLIST_AFTER_ROTATION': True,
}
8 changes: 5 additions & 3 deletions Django/NoUgly/NoUgly/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
urlpatterns = [
path('admin/', admin.site.urls),
path('store/', include('store.urls')),
path('user/', include('accounts.urls')),
path('accounts/', include('accounts.urls')),
# 로그인, 로그아웃, 비밀번호 재설정 및 비밀번호 변경과 같은 기본 인증 기능이 있습니다.
path('rest-auth/', include('rest_auth.urls')),
path('accounts/', include('dj_rest_auth.urls')),
path('accounts/', include('allauth.urls')),

# 등록 및 소셜 미디어 인증과 관련된 논리가 있습니다.
path('rest-auth/registration/', include('rest_auth.registration.urls')),
path('accounts/registration/', include('dj_rest_auth.registration.urls')),

]

Expand Down
18 changes: 18 additions & 0 deletions Django/NoUgly/accounts/migrations/0002_alter_user_gender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.8 on 2022-03-08 16:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='user',
name='gender',
field=models.CharField(choices=[('여', '여자'), ('남', '남자')], max_length=20),
),
]
18 changes: 18 additions & 0 deletions Django/NoUgly/accounts/migrations/0003_alter_user_gender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.8 on 2022-03-08 16:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0002_alter_user_gender'),
]

operations = [
migrations.AlterField(
model_name='user',
name='gender',
field=models.CharField(choices=[('남', '남자'), ('여', '여자')], max_length=20),
),
]
18 changes: 18 additions & 0 deletions Django/NoUgly/accounts/migrations/0004_alter_user_gender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.8 on 2022-03-10 23:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0003_alter_user_gender'),
]

operations = [
migrations.AlterField(
model_name='user',
name='gender',
field=models.CharField(choices=[('여', '여자'), ('남', '남자')], max_length=20),
),
]
18 changes: 18 additions & 0 deletions Django/NoUgly/accounts/migrations/0005_user_user_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.8 on 2022-03-11 20:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0004_alter_user_gender'),
]

operations = [
migrations.AddField(
model_name='user',
name='user_type',
field=models.CharField(default='basic', max_length=50),
),
]
18 changes: 18 additions & 0 deletions Django/NoUgly/accounts/migrations/0006_alter_user_gender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.8 on 2022-03-12 16:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0005_user_user_type'),
]

operations = [
migrations.AlterField(
model_name='user',
name='gender',
field=models.CharField(choices=[('남', '남자'), ('여', '여자')], max_length=20),
),
]
18 changes: 18 additions & 0 deletions Django/NoUgly/accounts/migrations/0007_alter_user_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.8 on 2022-03-13 22:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0006_alter_user_gender'),
]

operations = [
migrations.AlterField(
model_name='user',
name='date',
field=models.DateField(blank=True, null=True),
),
]
4 changes: 2 additions & 2 deletions Django/NoUgly/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class User(AbstractBaseUser, PermissionsMixin):
('여', '여자')
}
name = models.CharField(max_length=15)
date = models.DateField(blank=True)
date = models.DateField(blank=True, null=True)

gender = models.CharField(max_length=20, choices=Gender_choices)

address = models.CharField(max_length=250, blank=True, null=True)
phone_num = models.CharField(
max_length=16, blank=True, null=True, unique=True)

user_type = models.CharField(max_length=50, default='basic')
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

Expand Down
10 changes: 9 additions & 1 deletion Django/NoUgly/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.urls import path, include
from .views import *
from rest_framework.routers import DefaultRouter

Expand All @@ -7,4 +8,11 @@
router.register(r'destination', DestinationViewSet)


urlpatterns = router.urls
urlpatterns = [
path('', include(router.urls)),
path('login/kakao/', kakao_login, name='kakao_login'),
path('login/kakao/callback/', kakao_callback, name='kakao_callback'),
path('login/kakao/django', KakaoToDjangoLogin.as_view(),
name='kakao_django_login'),

]
Loading