2018-10-26 19:08:01 +00:00
|
|
|
from django.shortcuts import render
|
2018-11-17 21:15:17 +00:00
|
|
|
|
2018-11-17 10:21:35 +00:00
|
|
|
from rest_framework import viewsets
|
2018-11-17 17:48:12 +00:00
|
|
|
from rest_framework.parsers import JSONParser
|
2018-11-17 21:15:17 +00:00
|
|
|
from rest_framework.decorators import action
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
2018-10-26 19:08:01 +00:00
|
|
|
|
2018-11-17 20:54:59 +00:00
|
|
|
from django.http import HttpResponse, JsonResponse
|
2018-11-17 10:21:35 +00:00
|
|
|
|
2018-11-17 20:54:59 +00:00
|
|
|
from otpauth.serializer import VerifySerializer, OTPSerializer
|
|
|
|
from otpauth.models import OTPSeed
|
2018-11-17 10:39:42 +00:00
|
|
|
|
2018-11-17 20:54:59 +00:00
|
|
|
class OTPVerifyViewSet(viewsets.ModelViewSet):
|
|
|
|
serializer_class = OTPSerializer
|
|
|
|
queryset = OTPSeed.objects.all()
|
2018-11-17 17:48:12 +00:00
|
|
|
|
2018-11-17 21:15:17 +00:00
|
|
|
@action(detail=False, methods=['post'])
|
|
|
|
def verify(self, request):
|
|
|
|
serializer = VerifySerializer(data=request.data)
|
|
|
|
if serializer.is_valid():
|
|
|
|
print(serializer)
|
2018-11-17 21:53:51 +00:00
|
|
|
serializer.save()
|
2018-11-17 21:15:17 +00:00
|
|
|
return Response({'status': 'OK'})
|
|
|
|
|
|
|
|
return JsonResponse(serializer.errors, status=400)
|
|
|
|
|
2018-11-17 17:48:12 +00:00
|
|
|
|
|
|
|
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 []
|