Compare commits
2 Commits
b8ab991a4f
...
665fbf852a
Author | SHA1 | Date |
---|---|---|
Cayo Puigdefabregas | 665fbf852a | |
Cayo Puigdefabregas | 9dfaf0f60b |
18
api/views.py
18
api/views.py
|
@ -29,14 +29,14 @@ def NewSnapshot(request):
|
||||||
return JsonResponse({'error': 'Invalid request method'}, status=400)
|
return JsonResponse({'error': 'Invalid request method'}, status=400)
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
# auth_header = request.headers.get('Authorization')
|
auth_header = request.headers.get('Authorization')
|
||||||
# if not auth_header or not auth_header.startswith('Bearer '):
|
if not auth_header or not auth_header.startswith('Bearer '):
|
||||||
# return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||||
|
|
||||||
# token = auth_header.split(' ')[1]
|
token = auth_header.split(' ')[1]
|
||||||
# tk = Token.objects.filter(token=token).first()
|
tk = Token.objects.filter(token=token).first()
|
||||||
# if not tk:
|
if not tk:
|
||||||
# return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||||
|
|
||||||
# Validation snapshot
|
# Validation snapshot
|
||||||
try:
|
try:
|
||||||
|
@ -60,9 +60,7 @@ def NewSnapshot(request):
|
||||||
# save_in_disk(data, tk.user)
|
# save_in_disk(data, tk.user)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Build(data, tk.user)
|
Build(data, tk.user)
|
||||||
user = User.objects.get(email="user@example.org")
|
|
||||||
Build(data, user)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return JsonResponse({'status': 'fail'}, status=200)
|
return JsonResponse({'status': 'fail'}, status=200)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from user.models import Institution
|
from user.models import Institution
|
||||||
|
from api.models import Token
|
||||||
|
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
@ -28,3 +31,6 @@ class Command(BaseCommand):
|
||||||
)
|
)
|
||||||
self.u.set_password(self.password)
|
self.u.set_password(self.password)
|
||||||
self.u.save()
|
self.u.save()
|
||||||
|
token = uuid4()
|
||||||
|
Token.objects.create(token=token, owner=self.u)
|
||||||
|
print(f"TOKEN: {token}")
|
||||||
|
|
Loading…
Reference in New Issue