-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from EventAccess/pr-nfctag-scanned-1
Add API endpoint to check ticket validity
- Loading branch information
Showing
7 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.py[ocd] | ||
**/.env | ||
*.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from base64 import b16decode, b16encode | ||
|
||
|
||
class BinaryHexConverter: | ||
regex = "(?:[0-9a-fA-F]{2})+" | ||
|
||
def to_python(self, value: str) -> bytes: | ||
return b16decode(value, casefold=True) | ||
|
||
def to_url(self, value: bytes) -> str: | ||
return b16encode(value).decode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path, register_converter | ||
|
||
from . import views, converters | ||
|
||
register_converter(converters.BinaryHexConverter, "hex") | ||
|
||
urlpatterns = [ | ||
path("nfctag/<hex:tag>", views.scanned), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
from django.shortcuts import render | ||
from django.views.decorators.http import require_POST | ||
from django.views.decorators.cache import never_cache | ||
from django.http import JsonResponse | ||
|
||
# Create your views here. | ||
from database.models import Attendant | ||
|
||
|
||
@require_POST | ||
@never_cache | ||
def scanned(request, tag: bytes): | ||
try: | ||
attendant = Attendant.objects.get(tag=tag) | ||
# TODO: Queue event | ||
return JsonResponse({"valid": attendant.is_valid}, status=202) | ||
|
||
except Attendant.DoesNotExist: | ||
return JsonResponse({"error": "No such tag"}, status=404) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
DJANGO_SETTINGS_MODULE = config.settings | ||
python_files = tests.py test_*.py *_tests.py |