2018-10-26 21:08:01 +02:00
|
|
|
from django.shortcuts import render
|
2018-11-17 22:15:17 +01:00
|
|
|
|
2018-11-17 11:21:35 +01:00
|
|
|
from rest_framework import viewsets
|
2018-11-17 22:15:17 +01:00
|
|
|
from rest_framework.decorators import action
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
2018-11-18 13:42:16 +01:00
|
|
|
from django.http import JsonResponse
|
2018-11-17 21:54:59 +01:00
|
|
|
from otpauth.serializer import VerifySerializer, OTPSerializer
|
|
|
|
from otpauth.models import OTPSeed
|
2018-11-17 11:39:42 +01:00
|
|
|
|
2018-12-24 20:28:21 +01:00
|
|
|
|
2018-11-17 21:54:59 +01:00
|
|
|
class OTPVerifyViewSet(viewsets.ModelViewSet):
|
|
|
|
serializer_class = OTPSerializer
|
|
|
|
queryset = OTPSeed.objects.all()
|
2018-11-17 18:48:12 +01:00
|
|
|
|
2018-11-17 22:15:17 +01:00
|
|
|
@action(detail=False, methods=['post'])
|
|
|
|
def verify(self, request):
|
2018-12-24 20:58:08 +01:00
|
|
|
"""the standard serializer above already verified that
|
|
|
|
(name, realm, token) is valid.
|
|
|
|
|
|
|
|
Now we inspect the verify-prefixed names and return ok,
|
|
|
|
if they also verify
|
|
|
|
"""
|
|
|
|
|
2018-11-17 22:15:17 +01:00
|
|
|
serializer = VerifySerializer(data=request.data)
|
|
|
|
if serializer.is_valid():
|
2018-11-17 22:53:51 +01:00
|
|
|
serializer.save()
|
2018-11-17 22:15:17 +01:00
|
|
|
return Response({'status': 'OK'})
|
|
|
|
|
|
|
|
return JsonResponse(serializer.errors, status=400)
|