Add general viewset/serializer for otpseed

This commit is contained in:
Nico Schottelius 2018-11-17 21:54:59 +01:00
parent cdb45bd1f0
commit 414f688195
3 changed files with 12 additions and 25 deletions

View file

@ -3,22 +3,10 @@ from otpauth.models import OTPSeed
import pyotp
import otpauth
# class OTPSerializer(serializers.ModelSerializer):
# class Meta:
# model = OTPSeed
# fields = ('name', 'realm')
# token = serializers.CharField(max_length=128)
# verifyname = serializers.CharField(max_length=128)
# verifytoken = serializers.CharField(max_length=128)
# verifyrealm = serializers.CharField(max_length=128)
# class VerifySerializer(serializers.ModelSerializer):
# class Meta:
# model = OTPSeed
# fields = ('name', 'realm', 'token', 'verifyname', 'verifytoken', 'verifyrealm')
class OTPSerializer(serializers.ModelSerializer):
class Meta:
model = OTPSeed
fields = ('name', 'realm')
class VerifySerializer(serializers.Serializer):
name = serializers.CharField(max_length=128)

View file

@ -1,16 +1,15 @@
from django.shortcuts import render
from rest_framework import viewsets
from rest_framework.parsers import JSONParser
from otpauth.serializer import VerifySerializer
from django.http import HttpResponse, JsonResponse
import json
from otpauth.serializer import VerifySerializer, OTPSerializer
from otpauth.models import OTPSeed
class ModelVerifyViewSet(viewsets.ModelViewSet):
serializer_class = VerifySerializer
def get_queryset(self):
return None
class OTPVerifyViewSet(viewsets.ModelViewSet):
serializer_class = OTPSerializer
queryset = OTPSeed.objects.all()
class VerifyViewSet(viewsets.ViewSet):

View file

@ -21,12 +21,12 @@ from django.conf.urls import url, include
from django.contrib.auth.models import User
from rest_framework import routers, serializers, viewsets
from otpauth.models import OTPSeed
from otpauth.views import ModelVerifyViewSet, VerifyViewSet
from otpauth.views import OTPVerifyViewSet, VerifyViewSet
router = routers.DefaultRouter()
router.register(r'ungleichotp', VerifyViewSet, basename='ungleichotp')
router.register(r'ungleichotpv2', ModelVerifyViewSet, basename='ungleichotpv2')
router.register(r'ungleichotpv2', OTPVerifyViewSet, basename='ungleichotpv2')
print(router.urls)