From bd44438277a27dee8ddeddf66c02646317c00fc5 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 10 Nov 2018 21:40:09 -0700 Subject: [PATCH] GET authorized cards for each MAC --- authserver/README.md | 18 ++++++++++++++++++ authserver/authserver/api/views.py | 7 +++++++ authserver/authserver/urls.py | 1 + 3 files changed, 26 insertions(+) diff --git a/authserver/README.md b/authserver/README.md index 41c29ef..96ba8e6 100644 --- a/authserver/README.md +++ b/authserver/README.md @@ -124,6 +124,24 @@ Example response: } ``` +#### GET `/cards/[MAC]/` + +Returns all card numbers authorized to use a machine based on MAC address. + +Card numbers are on one line separated by a comma. + +Example request: + +``` +curl http://tools-auth.protospace.ca/cards/2C3AE843A15F/ +``` + +Example response: + +``` +"00000B8567,00000A4123,00000C9999" +``` + ### For authenticated users #### GET `/user/` diff --git a/authserver/authserver/api/views.py b/authserver/authserver/api/views.py index 7cac84b..3fb18ac 100644 --- a/authserver/authserver/api/views.py +++ b/authserver/authserver/api/views.py @@ -76,6 +76,13 @@ def login(request): return Response({'token': token.key}, status=status.HTTP_200_OK) +@api_view(["GET"]) +def cards(request, mac): + cards = models.Card.objects.all().filter(profile__authorized_tools__mac=mac) + card_numbers = [card.number for card in cards] + + return Response(','.join(card_numbers), status=status.HTTP_200_OK) + @api_view(["PUT"]) @permission_classes((IsLockoutAdmin,)) def update_cards(request): diff --git a/authserver/authserver/urls.py b/authserver/authserver/urls.py index fd72586..1d67cf7 100644 --- a/authserver/authserver/urls.py +++ b/authserver/authserver/urls.py @@ -34,6 +34,7 @@ urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), url(r'^login/', views.login), + url(r'^cards/(?P.*)/', views.cards), url(r'^update-cards/', views.update_cards) ]