Skip to content

Commit

Permalink
Formatting for Add/Remove ORCID
Browse files Browse the repository at this point in the history
updated dev DB
Related to biocompute-objects/portal_userdb#90
Changes to be committed:
	modified:   admin_only/db.sqlite3.dev
	modified:   authentication/apis.py
  • Loading branch information
HadleyKing committed Jun 8, 2023
1 parent 70f95f3 commit dd2af7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Binary file modified admin_only/db.sqlite3.dev
Binary file not shown.
33 changes: 26 additions & 7 deletions authentication/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,33 @@ def post(self, request):
auth_object = Authentication.objects.get(username=request.user.username)

if request.data in auth_object.auth_service:
return Response(status=status.HTTP_409_CONFLICT, data={"message": "That object already exists for this account."})
return Response(
status=status.HTTP_409_CONFLICT,
data={"message": "That object already exists for this account."}
)
auth_object.auth_service.append(request.data)
auth_object.save()
return Response(status=status.HTTP_200_OK, data={"message": "Authentication added to existing object"})
return Response(
status=status.HTTP_200_OK,
data={"message": "Authentication added to existing object"}
)

except Authentication.DoesNotExist:
auth_object = Authentication.objects.create(
username=request.user,
auth_service=[request.data]
)
print('status=status.HTTP_201_CREATED')
return Response(status=status.HTTP_201_CREATED, data={"message": "Authentication object added to account"})
return Response(
status=status.HTTP_201_CREATED,
data={"message": "Authentication object added to account"}
)

except Exception as err:
return Response(status=status.HTTP_400_BAD_REQUEST, data={"message": err})
return Response(
status=status.HTTP_400_BAD_REQUEST,
data={"message": err}
)

class RemoveAuthenticationApi(APIView):
"""
Expand Down Expand Up @@ -206,12 +218,16 @@ class RemoveAuthenticationApi(APIView):
},
tags=["Authentication"],
)

def post(self, request):
""""""

result = validate_auth_service(request.data)

if result != 1:
return Response(status=status.HTTP_400_BAD_REQUEST, data=result)
return Response(
status=status.HTTP_400_BAD_REQUEST,
data=result
)
try:
auth_object = Authentication.objects.get(username=request.user.username)
except Authentication.DoesNotExist:
Expand All @@ -226,7 +242,10 @@ def post(self, request):
)
auth_object.auth_service.remove(request.data)
auth_object.save()
return Response(status=status.HTTP_200_OK, data={"message": "Authentication object removed."})
return Response(
status=status.HTTP_200_OK,
data={"message": "Authentication object removed."}
)

class ResetTokenApi(APIView):
"""Reset Token
Expand Down

0 comments on commit dd2af7b

Please sign in to comment.