GET authorized cards for each MAC

This commit is contained in:
Tanner Collin 2018-11-10 21:40:09 -07:00
parent 790725c29e
commit bd44438277
3 changed files with 26 additions and 0 deletions

View File

@ -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/`

View File

@ -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):

View File

@ -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<mac>.*)/', views.cards),
url(r'^update-cards/', views.update_cards)
]