43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from django.shortcuts import render
|
|
|
|
from rest_framework import viewsets
|
|
from rest_framework.parsers import JSONParser
|
|
from rest_framework.decorators import action
|
|
from rest_framework.response import Response
|
|
|
|
|
|
from django.http import HttpResponse, JsonResponse
|
|
|
|
from otpauth.serializer import VerifySerializer, OTPSerializer
|
|
from otpauth.models import OTPSeed
|
|
|
|
class OTPVerifyViewSet(viewsets.ModelViewSet):
|
|
serializer_class = OTPSerializer
|
|
queryset = OTPSeed.objects.all()
|
|
|
|
@action(detail=False, methods=['post'])
|
|
def verify(self, request):
|
|
serializer = VerifySerializer(data=request.data)
|
|
if serializer.is_valid():
|
|
print(serializer)
|
|
return Response({'status': 'OK'})
|
|
|
|
return JsonResponse(serializer.errors, status=400)
|
|
|
|
|
|
class VerifyViewSet(viewsets.ViewSet):
|
|
serializer_class = VerifySerializer
|
|
|
|
def create(self, request):
|
|
data = JSONParser().parse(request)
|
|
serializer = VerifySerializer(data=data)
|
|
if serializer.is_valid():
|
|
print("is valid")
|
|
print(serializer)
|
|
#serializer.save()
|
|
return JsonResponse(serializer.data, status=201)
|
|
return JsonResponse(serializer.errors, status=400)
|
|
|
|
|
|
def get_queryset(self):
|
|
return []
|