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

๐Ÿ”€: main๊ณผ develop ๋ธŒ๋žœ์น˜ ๋ณ‘ํ•ฉ #75

Merged
merged 9 commits into from
Jul 3, 2024
1 change: 0 additions & 1 deletion GHJM/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@
path('bucket-list/', include('bucket_list.urls')),
path('monthly-goal/', include('monthly_goal.urls')),
]

8 changes: 4 additions & 4 deletions accounts/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def __call__(self, request):
id = payload.get('user_id')

# ์ถ”์ถœ๋œ ์‚ฌ์šฉ์ž ์‹๋ณ„ ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž๋ฅผ ๊ฐ€์ ธ์˜ด.
user = CustomUser.objects.get(id=id)
try:
user = CustomUser.objects.get(id=id)
except CustomUser.DoesNotExist:
return JsonResponse({'error': 'ํ•ด๋‹น id์— ๋Œ€ํ•œ user ๊ฐ์ฒด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.'}, status=404)

# ์ธ์ฆ์ด ์„ฑ๊ณตํ•˜๋ฉด ์š”์ฒญ์— ์‚ฌ์šฉ์ž๋ฅผ ํ• ๋‹น.
request.user = user
Expand All @@ -61,6 +64,3 @@ def check_path_to_exclude_middleware(self, path):
if each_path in path:
return True
return False



5 changes: 3 additions & 2 deletions accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
urlpatterns = [
path('kakao/login/', views.kakao_login),
path('kakao/login/callback/', views.KakaoCallbackView.as_view()),
path('token/refresh/', views.reissue_token),
path('logout/', views.logout)
path('reissue-token/', views.reissue_token),
path('logout/', views.logout),
path('my/', views.delete_user)
]
14 changes: 12 additions & 2 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from jwt import DecodeError, ExpiredSignatureError, InvalidTokenError
from .jwt import generate_access_token, generate_refresh_token, decode_token, get_token_exp,save_refresh_token, get_token_exp_in_str_format
from GHJM.json_response_setting import JsonResponse
from django.views.decorators.http import require_http_methods
import requests

REFRESH_TOKEN = 'refresh-token'
Expand All @@ -34,7 +35,7 @@ def get(self, request):
token_data = token_response.json()

if 'error' in token_data:
return JsonResponse({'error': token_data['error']}, status=status.HTTP_400_BAD_REQUEST)
return JsonResponse({'error': token_data['error']}, status=400)

access_token = token_data.get("access_token")

Expand Down Expand Up @@ -78,7 +79,7 @@ def get(self, request):
return JsonResponse(response_data)



require_http_methods(['POST'])
def reissue_token(request):
refresh_token = request.headers.get(REFRESH_TOKEN)

Expand Down Expand Up @@ -110,6 +111,7 @@ def reissue_token(request):
return JsonResponse(response_data)


@require_http_methods(['DELETE'])
# user๊ฐ€ ๋กœ๊ทธ์•„์›ƒ ๋ฒ„ํŠผ์„ ์ง์ ‘ ํด๋ฆญ ํ–ˆ์„ ๊ฒฝ์šฐ
def logout(request):
refresh_token = request.headers.get(REFRESH_TOKEN)
Expand All @@ -130,3 +132,11 @@ def logout(request):
cache.delete(user_id)

return JsonResponse({'message': '๋กœ๊ทธ์•„์›ƒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'}, status=204)


@require_http_methods(['DELETE'])
def delete_user(request):
user = request.user
user.delete()

return JsonResponse({'Success': 'ํšŒ์›ํƒˆํ‡ด๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'})
Loading