Skip to content

Commit

Permalink
feat: 재학생 인증 API 수정 (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunmin0317 committed Feb 10, 2024
1 parent ba2f645 commit 16ed451
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from sangmyung_univ_auth import auth, completed_courses
from sangmyung_univ_auth import auth, completed_courses, auth_detail

from api.serializers import UserSerializer

Expand All @@ -13,7 +13,7 @@ def authenticate(request):

@api_view(['POST'])
def userinfo(request):
return authenticate_user(request, response_body=False)
return authenticate_user(request, is_detail=True)


@api_view(['POST'])
Expand All @@ -28,13 +28,14 @@ def courses(request):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


def authenticate_user(request, response_body=True):
def authenticate_user(request, is_detail=False):
serializer = UserSerializer(data=request.data)
if serializer.is_valid():
username, password = serializer.validated_data['username'], serializer.validated_data['password']
result = auth(username, password)
func = auth_detail if is_detail else auth
result = func(username, password)
status_code = status.HTTP_200_OK if result.is_auth else status.HTTP_401_UNAUTHORIZED
return Response(result._asdict() if response_body else result.body, status=status_code)
return Response(result.body if is_detail else result._asdict(), status=status_code)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


Expand Down

0 comments on commit 16ed451

Please sign in to comment.